Using Slurm with Cronjobs

You may have noticed that users of MSI are not allowed to schedule scripts to run with cronjobs. Good news! MSI has the scrontab module that behaves just like a cronjob but employs Slurm.

What is a cronjob?

Cronjobs are standard to most linux distributions. They let you run commands at regularly scheduled times. The command crontab -e is used to edit a user's crontab, the file that the user uses to interface with the cron daemon. Crontabs follow a specific syntax to set times to run.

Crontab syntax

Each command in a crontab begins with 5 fields that are numbers or sets/ranges of numbers that correspond to times. The five numbers are seperated by spaces and go as follows: minute hour day-of-month month day-of-week.

Hours are based on the system time in a 24 hour clock.

Besides numbers, 4 symbols are allowed.

  • * any value

  • , value list separator

  • - range of values

  • / step values

For instance 23 14 8-14 * * will run at 14:23 on every day of the month from the 8th to the 14th.

Check out crontab guru for more information on crontab syntax. Click random a handful of times to see what is possible!

Using Crontab syntax with Slurm

Slurm adopts crontab syntax with its scrontab module.

To edit a scrontab use the command scrontab -e. This will open a file in Vim that you can add commands to.

scron combines crontab syntax and sbatch syntax. Before the line running a script put you sbatch parameters as normal, but changing #SBATCH to #SCRON

Here is an example of a scrontab

#SCRON --time=30:00
#SCRON --mem=10g
#SCRON --tmp=10g
#SCRON --mail-type=ALL  
#SCRON --mail-user=user500@umn.edu
#SCRON -J scronjob
#SCRON -A feczk001
#SCRON -o /path/to/logs/%A_scronjob.out

0 14 * * * /full/path/to/script.sh

scron on MSI

MSI's system time is central time, not UTC time. Use the command date in a terminal to see what time it is on MSI right now.

Only one scronjob can be set at a time. It seems that when multiple entries are included in the scrontab only the first is parsed and added to the queue. If running of multiple scripts is needed, consider scheduling a script that runs other scripts or submits sbatches.

Jobs created with scrontab are assigned a single job id.

  • When cancelled all future runs of the job will also be cancelled.

  • Logs generated by the -o or -e flags with the %A parameter will overwrite the same file every run.

  • Opening the scrontab with crontab -e (even if not updated or saved) cancels the old job and creates a new job id.

scrontab attempts to run things on schedule but is subject to resource limitations like other slurm jobs. Some jobs may not run exactly when specified.