Skip to content

Recurring Jobs (scrontab)

Exercises

  1. 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
Then edit your scrontab with `scrontab -e` and add:
#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
Use absolute paths for all files in scrontab entries.
  1. 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
# List your scrontab
scrontab -l

# Find the cron job in the queue
squeue --me --name=hourly_check
  1. 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

References