CRON job that run every 130 seconds

h_a86

Is it possible to create a CRON job that can run every 130 secs or 2 min and 10 secs.

Argonauts

If you are on a systemd distro you can use a systemd timer to get this level of timing resolution. Depending on your use case, you can use it as a delta-t (eg every x seconds since boot) or configure it using wall time ( eg at 00:00:10, 00:02:10, etc.).

Briefly, you would create 2 files.

  1. The first is the .timer file, described here. This will set up the timing of the timer events and configure what happens when the timing event occurs. There are a number of criteria to define - for example - do you want it to run immediately at boot and then every 130 seconds? Do you want it to run if it you are at a lower run level? Do you want it to continue to run if it encountered errors? Systemd gets, arguably, complex far quicker than the old approachs with init files and cron jobs. However, using it instead of cron will resolve your timing issue.

  2. The second file is typically a .service file that gets called by the timer service. In this file you would define what the cron job does - either a simple command or call another script to allow more sophisticated tasks. This service file would normally be setup as a 'oneshot'. See here for more details.

The files should be copied into /etc/systemd/system/ and you will run the following to enable / start the timer service:

 systemctl enable mycronjob.timer
 systemctl start mycronjob.timer

You can use journalctl to review / debug your implementation. For far more information, see the archwiki discussion.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related