Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cron: running cron every 1 second?

Tags:

linux

cron

How can I run cron every 1 second? there's only minutes option by default

like image 450
Crazy_Bash Avatar asked Dec 05 '22 18:12

Crazy_Bash


2 Answers

Let cron start the job one time, the first time. Put the program in an infinite loop, sleep() for 1 second at the end of each loop. like this, in C:

  int main( int argc, char ** argv ) {
      while (1) {
        // do the work
        sleep(1000);
      }
  }

Could that work?

like image 55
Pete Wilson Avatar answered Dec 08 '22 16:12

Pete Wilson


Cron executes stuff every minute. Use a script:

while :
do
    sleep 1
    some_command || break
done

or in one line:

while : ; do sleep 1 ; some_command || break ; done

This will wait 1 second in between each execution, so if your command takes .75 seconds to run, then this script will kick it off every 1.75 seconds.

like image 44
UtahJarhead Avatar answered Dec 08 '22 14:12

UtahJarhead