Running a cron every 30 seconds

后端 未结 19 1177
面向向阳花
面向向阳花 2020-11-22 10:56

Ok so I have a cron that I need to run every 30 seconds.

Here is what I have:

*/30 * * * * /bin/bash -l -c \'cd /srv/last_song/releases/2012030813315         


        
19条回答
  •  一整个雨季
    2020-11-22 11:30

    Cron job cannot be used to schedule a job in seconds interval. i.e You cannot schedule a cron job to run every 5 seconds. The alternative is to write a shell script that uses sleep 5 command in it.

    Create a shell script every-5-seconds.sh using bash while loop as shown below.

    $ cat every-5-seconds.sh
    #!/bin/bash
    while true
    do
     /home/ramesh/backup.sh
     sleep 5
    done
    

    Now, execute this shell script in the background using nohup as shown below. This will keep executing the script even after you logout from your session. This will execute your backup.sh shell script every 5 seconds.

    $ nohup ./every-5-seconds.sh &
    

提交回复
热议问题