Skip to main content

Running recurring jobs with scrontab

NOTE 

THIS IS A WORK IN PROGRESS!

How to schedule jobs with SLURM

 Using `scrontab` with SLURM: Periodic Job Scheduling

In SLURM, `scrontab` is a tool that allows users to schedule **periodic jobs** using a familiar cron-like syntax. This is useful for automating recurring SLURM job submissions, such as daily simulations, log checks, or cleanup tasks.

---

##  What Is `scrontab`?

`scrontab` is SLURM's periodic scheduling system, similar to Unix `crontab`. It schedules recurring executions of SLURM jobs by submitting them through `sbatch`.

To use `scrontab`, your SLURM system must have periodic scheduling enabled (`EnablePeriodicJobSubmit` in `slurm.conf`) and accounting via `slurmdbd`.

---

##  Basic Usage Pattern

- Use `sbatch` in the **scrontab file** to submit a SLURM batch script.
- The **SLURM batch script** defines the job details and execution logic.
- Do **not** put `sbatch` inside your batch script.

---

## Example 1: Run a Job Daily at 3:30 AM

### 1. SLURM Batch Script (`daily_job.sh`)

```bash
#!/bin/bash
#SBATCH --job-name=dailyjob
#SBATCH --output=dailyjob.out
#SBATCH --time=00:10:00
#SBATCH --mem=1G

# Your job logic here
python /home/user/scripts/daily_task.py

2. Scrontab File (daily.scron)

30 3 * * * sbatch /home/user/daily_job.sh

3. Install the Scrontab

scrontab daily.scron

```

1. SLURM Batch Script (weekly_log_check.sh)

#!/bin/bash
#SBATCH --job-name=logcheck
#SBATCH --output=logcheck.out
#SBATCH --time=00:05:00
#SBATCH --mem=512M

python /home/user/scripts/check_logs.py

2. Scrontab File (weekly.scron)

0 6 * * 1 sbatch /home/user/weekly_log_check.sh

3. Install the Scrontab

scrontab weekly.scron

 Maintenance Commands

    View current scrontab:

scrontab -l

Remove current scrontab:

scrontab -r

Do not call sbatch from inside your SLURM job script. The job is already submitted via sbatch from the scrontab.

 

Let’s say you want to submit a job every day at 3:30 AM.

Here is an example scrontab file (my.scron):

# Run my_daily_job.sh at 3:30 AM every day
30 3 * * * sbatch /home/user/my_daily_job.sh

Each line follows cron-style timing:

┌──────────── minute (0 - 59)
│ ┌────────── hour (0 - 23)
│ │ ┌──────── day of month (1 - 31)
│ │ │ ┌────── month (1 - 12)
│ │ │ │ ┌──── day of week (0 - 6) (Sunday=0)
│ │ │ │ │
│ │ │ │ │
30 3 * * * <SLURM command here>