Skip to main content

Running recurring jobs with scrontab

NOTE 

THIS IS A WORK IN PROGRESS!

Scheduling

HowRecurring toJobs scheduleon jobsGRIT HPC with SLURM

scrontab

GRIT UsingHPC `scrontab`supports withperiodic SLURM:job Periodicscheduling Jobusing Scheduling

Slurm’s

Inscrontab SLURM, `scrontab` is a tool thatfeature.
This allows users to run jobs on a schedule **periodic jobs** using acron-style 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,syntax, similar to UnixLinux `crontab`. It schedules recurring executions of SLURM jobs by submitting them through `sbatch`crontab.

ToTypical useuses `scrontab`,include:

your
    SLURM
  • system

    Automated mustdata haveprocessing

  • Periodic log analysis

  • Monitoring workflows

  • Triggering simulations when new data arrives

  • Cleanup or maintenance scripts


What is scrontab?

scrontab is Slurm’s periodic schedulingjob enabled (`EnablePeriodicJobSubmit` in `slurm.conf`) and accounting via `slurmdbd`scheduler.

---Instead of running commands directly like Linux cron, scrontab typically runs sbatch commands, which submit jobs to the Slurm scheduler.

##This ensures scheduled jobs:

  • obey cluster scheduling policies

  • respect fairshare

  • run on compute nodes rather than login nodes


Basic UsageWorkflow

Pattern

The typical workflow is:

-

Use
`sbatch`
in
the
**
scrontab file**schedule

sbatch tocommand

Slurm submitscheduler

Compute anode SLURMjob execution

A scheduled job therefore consists of two parts:

  1. A Slurm batch script.
    - The **SLURM batch script** defines the job details and execution logic.
    - Do **not** put `sbatch` inside your batch script.script

  2. ---A scrontab entry that submits it

    ##

  3. Example
1:

Example: Run a Job Daily at 3:30 AM

Step 1 — Create a Slurm Job Script

daily_job.sh

###

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

```bash

#!/bin/bash
#SBATCH --job-name=dailyjobdaily_job
#SBATCH --partition=grit_nodes
#SBATCH --account=slurm_users
#SBATCH --output=dailyjob.%x-%j.out
#SBATCH --time=00:10:00
#SBATCH --mem=1G


#SBATCH

#--cpus-per-task=1

echo Your"Starting job logicat here$(date)"

python /home/user/$USER/scripts/daily_task.py

echo "Finished at $(date)"



Step 2 — Create a scrontab File

daily.scron

2.

Scrontab
File
(daily.scron)

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

This runs every day at 03:30.

3.


Step 3 — Install the Scrontab

scrontab

scrontab daily.scron


Example: Weekly Job

Run a job every Monday at 6:00 AM

```scron entry:

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.$USER/weekly_job.sh



Recommended Pattern: Lightweight Check Jobs

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 sayOften you want to submitrun a small check frequently, but only launch a large compute job when needed.

This avoids wasting cluster resources.

Example use cases:

  • run analysis when new data arrives

  • trigger pipelines when files appear

  • monitor experiment output


Example: Periodic Check That Launches a Large Job

scrontab entry

Run every day5 at 3:30 AM.minutes:

Here

is
an
example
scrontab
file
(my.scron):

#

Run
my_daily_job.sh
at
3:30 AM every day
30 3
*/5 * * * sbatch* /home/user/my_daily_job.$USER/bin/check_and_submit.sh


Check Script

check_and_submit.sh

#!/usr/bin/env bash
set -euo pipefail

JOB_NAME="data_pipeline"
PARTITION="grit_nodes"
ACCOUNT="slurm_users"

# Example condition:
# run job if files exist in incoming folder

if ! find /data/incoming -type f | grep -q .; then
exit 0
fi

# Prevent duplicate submissions
if squeue -h -u "$USER" -n "$JOB_NAME" -t PD,R | grep -q .; then
exit 0
fi

echo "Submitting pipeline job..."

sbatch \
-J "$JOB_NAME" \
-A "$ACCOUNT" \
-p "$PARTITION" \
-c 8 \
--mem=32G \
-t 04:00:00 \
/home/$USER/bin/big_job.sh

EachThis line follows cron-style timing:script:

  1. Checks if work exists

  2. Ensures a job isn’t already queued

  3. Submits the larger compute job


Cron Time Syntax

scrontab uses standard cron syntax:

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

Example:

30 3 * * * sbatch my_job.sh

Runs daily at 03:30.


Managing scrontab

View your scheduled jobs

scrontab -l


Remove your scrontab

scrontab -r


Edit your scrontab interactively

scrontab -e


Best Practices on GRIT HPC

Keep scheduled jobs lightweight

scrontab jobs should:

  • run quickly

  • avoid large compute workloads

  • primarily submit jobs via sbatch


Avoid duplicate jobs

Always check if a job is already running:

squeue -u $USER


Use proper partitions

Typical settings on GRIT:

--partition=grit_nodes
--account=slurm_users


Log job output

Use standard Slurm logging:

#SBATCH --output=%x-%j.out


Example Use Cases on GRIT

Common ways researchers use scrontab:

Use caseDescription
Automated pipelinesProcess newly uploaded datasets
Sensor ingestionRun periodic data import jobs
Simulation restartsRelaunch long simulations
Cleanup jobsRemove temporary files
MonitoringCheck cluster experiment outputs

Summary

scrontab provides a simple way to schedule recurring Slurm jobs while still using the cluster scheduler.

Typical pattern:

scrontab schedule

lightweight check

sbatch submission

Slurm job runs on compute nodes

This allows users to automate workflows without running heavy workloads on login nodes.