0

The min time for a crond job is 1 minute, is there any package that has the same use as crontab and can set a second job

2 Answers2

0

You can do it with SystemD on most modern Linux distributions. Please see this topic and the SystemD-specific answer in it: Running a cron every 30 seconds

  • Thanks for the answer, I know that way, sleep with a delay, but does there any package that can do the second job itself? – forgaoqiang Jul 29 '21 at 02:54
0

Although there is no "real" way to run a job less than a minute with cron ... I have used this work-around for years with no issues. Say you wanted to run the cron every 30 secs. You set 2 processes to run every minute .. And set one to sleep for 30 secs. IE

* * * * *  sh /path/to/script/shell.sh
* * * * * ( sleep 30; sh /path/to/script/shell.sh )

Effectively running the cron every 30 seconds.

Conversely if you wanted it to run every 20 seconds:

* * * * *  sh /path/to/script/shell.sh
* * * * * ( sleep 20; sh /path/to/script/shell.sh )
* * * * * ( sleep 40; sh /path/to/script/shell.sh )

NOTE this is a work-around!

Zak
  • 6,976
  • 2
  • 26
  • 48