Job Scheduling In Linux
at
command→ at
command can be used to schedule a job to run at a specific time.
STEPS TO SCHEDULE JOB
We need to install
at
firstsudo apt-get install at
Once it is installed, We must start and enable it.
sudo systemctl start atd
sudo systemctl enable atd
To schedule the creation of an empty file, use the at command.
for example: To create a file 1 min from now
echo “touch/path/to/yourfile.txt” | at now +1 minute
Check the file has been created
ls
Limitation of at
command → We can’t use it to run recurring tasks.
CRONTAB
A crontab (short for cron table) is a configuration file in Unix-like systems used to schedule and automate tasks (jobs) to run at specified times or intervals. It’s managed by the cron daemon, a background service that executes the scheduled tasks. Each line in the crontab defines a task and the time when it should run, following a specific syntax.
Cron Daemon
The cron daemon is a background service in Unix-like operating systems that executes scheduled tasks at specified times. It continuously runs in the background, checking the crontab files for any jobs that need to be executed at the current time.
Crontab Syntax:
_ _ _ _ _ command
| | | | |—>Day of the week (0-7) (Sunday to Saturday)
| | | |———>Month (1-12)
| | |—————>Day of the month (1-31)
| |———————>Hour(0-23)
|—————————>Minute(0-59)
Example: 20 1 * * 2 /path/to/script.sh
This will run script located at /path/to/script.sh
every Tuesday at 1:20 am.
crontab demo:
open crontab file by using command
crontab -e
choose the editor , as per your need
* * * * * touch /home/ubuntu/file
This command will run every minute of every hour of everyday of every month and everyday of the week to create the file.The file created should be visible in home directory, check if the file has been created.
Linux Crontab is a powerful utility that is used for Scheduling and Automating Tasks in Unix-like operating systems. It facilitates the users to run the scripts or Linux Commands at specified times and intervals.
Subscribe to my newsletter
Read articles from shilpa tanga directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by