Recurring Jobs (scrontab)
Exercises¶
- Create a scrontab entry that runs every hour
Use scrontab -e to add an entry that runs a simple script every hour. The script should append the current date and hostname to a log file. Set resource limits of 10 minutes and 1G memory.
Hint / Solution
First create the script:cat > ~/scripts/hourly_check.sh << 'EOF'
#!/bin/bash
echo "$(date): Running on $(hostname)" >> ~/logs/hourly_check.log
EOF
chmod +x ~/scripts/hourly_check.sh
mkdir -p ~/logs
#SCRON --time=00:10:00
#SCRON --mem=1G
#SCRON -J hourly_check
#SCRON --output=/home/jdoe/logs/hourly_%j.out
@hourly /home/jdoe/scripts/hourly_check.sh
slurm-training-val (Slurm 25.11.4, ParallelCluster 3.15.0).
- List your scrontab entries
After creating an entry, verify it was saved by listing your scrontab. Also use squeue to find the associated job ID that Slurm created for your recurring job.
Hint / Solution
Expected output: Validated 2026-04-15 onslurm-training-val (Slurm 25.11.4, ParallelCluster 3.15.0).
$ scrontab -l
#SCRON --time=00:10:00
#SCRON --mem=1G
#SCRON -J val_scron_hourly
#SCRON --output=/home/ec2-user/logs/val_scron_hourly_%j.out
@hourly /home/ec2-user/scripts/val_scron_hourly.sh
$ squeue --me --name=val_scron_hourly || true
JOBID PARTITION NAME USER ST TIME NODES NODELIST(REASON)
691 batch val_scro ec2-user PD 0:00 1 (BeginTime)
- Remove a scrontab entry
Remove all your scrontab entries using scrontab -r. Verify the removal by listing again and checking that the associated job is no longer in the queue.
Hint / Solution
# Remove all entries
scrontab -r
# Verify removal
scrontab -l
# Should show an empty or commented-out scrontab
squeue --me --name=hourly_check
# Should return no results
slurm-training-val (Slurm 25.11.4, ParallelCluster 3.15.0).