Help - Search - Members - Calendar
Full Version: Cron Job To Run Every 20 Seconds
Linuxhelp > Support > Technical Support

Could somebody tell me how to set up a cronjob, for a RedHat Linux machine, that runs every 20 seconds?

I used the 'crontab' command to create the cronjab, and when I do 'crontab -l', the command that I entered is displayed. However, the job isn't running.

Cron runs every minute ... so you can't run something more frequently than every minute ... and it starts at exactly 00 seconds.

There are five fields and the command to execute ... the fields are:
field          allowed values
-----          --------------
minute            0-59
hour               0-23
day of month   1-31
month             1-12 (or names, see below)
day of week     0-7 (0 or 7 is Sun, or use names)

it looks like this in an entry:

min hr dom mon dow command_to_execute


05 12 * * 3 /bin/

would start the script /bin/ at 12:05pm every Wednesday
You could create 3 cron entries that look the same as the first one ... but they need to call 3 seperate files ...

file 1: does what you want...
file 2: has a line sleep 20 and all the stuff in file 1
file 3: has a line sleep 40 and all the stuff in file 1

the crontab entry would be:

0-59 * * * * path_to_file1
0-59 * * * * path_to_file2
0-59 * * * * path_to_file3

so file1 will execute on the minute at 00 seconds... file2 will start executing on the minute at 00, and sleep for 20 seconds then start ... file3 will execute at 00 and sleep for 40 seconds then execute.

Are you sure that what you want to do must be done every 20 seconds ... that seems very fast. Will the process be complete before it tries to start again? If not, you need to not start a process and potentially hang it until the other one is finished.
Thanks for the response.

I just wanted to know if it was feasible. The other option would be to code the application so that it starts, sleeps for a designated period, and then continues running. That option would elimate the need for the cronjob altogether.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2018 Invision Power Services, Inc.