Automatically Run a Command Every 5 Minutes
I'm very new to using Linux and especially with command line. I've managed to successfully get a Plex Media Server up and running but I need to run the following command every 5 minutes to sync with my Amazon Drive.
acd_cli sync
I've tried various different methods such as bash scripts and can't get it to work. I just need the command above to run every 5 minutes and it feels like there's an easy way which I don't know about.
You can use
crontab -e
to create a user cron schedule.
The line you specifically need is
*/5 * * * * /home/YOU/backup.sh
In backup.sh
add any commands you want to run, make sure the script is executable, i.e. chmod +x backup.sh
Have a look at
http://www.unixgeeks.org/security/newbie/unix/cron-1.html
Easy Method
You can set up a bash script that loops forever executing that command then sleeping for 5 minutes.
Open a terminal and execute this command:
sudo nano /usr/local/bin/amazon-sync
Then, type the following:
#!/bin/sh
while true
do
acd_cli sync
sleep 300
done
Press ctrl+o to save
Press ctrl+x to exit
Execute this command:
sudo chmod +x /usr/local/bin/amazon-sync
When you start up your computer press ctrl+alt+t and type amazon-sync
then minimize the terminal window. Command will run once every 5 minutes (300 seconds).
There's also watch
command, if you need to show output on screen and clear automatically.
watch -n 300 acd_cli sync
When you say 5 minutes, Do you mean 5 minutes or will you forget about the command In 5 minutes and leave It running Indefinitely
There's so many options to choose from, But I'll show you 4 clever ways to Implement this.
for (( i=0; i<=20; i++)); do 'acd_cli sync' $i ;sleep 300; done
This says that i Is 0, Then 0 Is less than 20, So It will minus 1 until It reaches 0. So It will run 20 times. Every 5 minutes
while true; do 'acd_cli sync'; sleep 300; done | at now +30 min
This says while true, do the command given every 5 minutes, Starting now for 30 minutes long, To run this command you'll need to Install at by running apt install at --assume-yes, Not exactly sure that this will work on a loop though
while true [ $i -lt 20 ]; do 'acd_cli sync' & i=$[$i+1];sleep 300; done
This command says, While $i remains lower than 20 do the Amazon Cloud Drive Command Line Interface you listed, Then i Is still i plus one on every occurrence of the command, Every 5 minutes forever
for i in $(seq 20); do 'acd_cli sync' $i; sleep 300; done
This says For the Input sequence 20 do the Amazon Cloud Drive sync, Every 5 minutes 20 times