Cron: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
(Add Crontab and Bash Script examples) |
||
Line 24: | Line 24: | ||
=== Crontab Options === | === Crontab Options === | ||
=== | == Examples == | ||
=== Initiating an Sbatch To Run A Bash Script === | |||
==== Bash Script ==== | |||
<pre> | |||
#!/bin/bash | |||
# resources | |||
#SBATCH cpus-per-task=1 | |||
#SBATCH mem-per-cpu=4G | |||
#SBATCH array=-1%1 | |||
#SBATCH partition=express | |||
# job name, error and output files | |||
#SBATCH --job-name=cron-job | |||
#SBATCH error=err_%j_4a.log | |||
#SBATCH output=out_%j_%4a.log | |||
#SBATCH ntasks=1 | |||
# email address to request notifications when the job is complete or if it fails | |||
#SBATCH --mail-type=FAIL | |||
#SBATCH --mail-user=$blazerid@uab.edu | |||
# store text file in the home directory | |||
echo "hi" > $HOME/test.txt | |||
</pre> | |||
==== Crontab File ==== | |||
<pre> | |||
#!/usr/bin/env | |||
# run generate_data.py | |||
# git add, commit, and push | |||
= | MAILTO=blazerid@uab.edu | ||
#git add data.csv | |||
#git commit -m "update data" | |||
#git push | |||
# submit script to queuing system | |||
# runs cronjob.sh every minute of every day | |||
* * * * * /cm/shared/apps/slurm/18.08.9/bin/sbatch /data/user/user_id/project_dir/cronjob.sh | |||
</pre> |
Revision as of 23:02, 9 March 2021
Cron
What Is Cron?
Cron is a unix time based job scheduler tool.
Overview
Crontab Syntax
Cron Expression Table
Cron actions are driven by a crontab file, also known as a "cron table". The user's crontab file is a configuration file that specifies shell commands to run at a given schedule.
Each line of a crontab file represents a job, and looks like this:
# ┌───────────── minute (0 - 59) # │ ┌───────────── hour (0 - 23) # │ │ ┌───────────── day of the month (1 - 31) # │ │ │ ┌───────────── month (1 - 12) # │ │ │ │ ┌───────────── day of the week (0 - 6) (Sunday to Saturday; # │ │ │ │ │ 7 is also Sunday on some systems) # │ │ │ │ │ # │ │ │ │ │ # * * * * * <command to execute>
Crontab Options
Examples
Initiating an Sbatch To Run A Bash Script
Bash Script
#!/bin/bash # resources #SBATCH cpus-per-task=1 #SBATCH mem-per-cpu=4G #SBATCH array=-1%1 #SBATCH partition=express # job name, error and output files #SBATCH --job-name=cron-job #SBATCH error=err_%j_4a.log #SBATCH output=out_%j_%4a.log #SBATCH ntasks=1 # email address to request notifications when the job is complete or if it fails #SBATCH --mail-type=FAIL #SBATCH --mail-user=$blazerid@uab.edu # store text file in the home directory echo "hi" > $HOME/test.txt
Crontab File
#!/usr/bin/env # run generate_data.py # git add, commit, and push MAILTO=blazerid@uab.edu #git add data.csv #git commit -m "update data" #git push # submit script to queuing system # runs cronjob.sh every minute of every day * * * * * /cm/shared/apps/slurm/18.08.9/bin/sbatch /data/user/user_id/project_dir/cronjob.sh