AMP AMP

How To Schedule a Cron Job to run Scripts in Debian 11.3

To Schedule a Cron Job to run Scripts in Debian 11.3

Introduction:

Scheduling a Job for a Specific Time The basic usage of cron is to execute a job in a specific time The cron daemon is a long-running process that executes commands at specific dates and times. You can use this to schedule activities, either as one-time events or as recurring tasks

Installation Steps:

Step1: Check the OS Version of Debian by using the below command

[root@linuxhelp ]# lsb_release -a

PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye

Step 2: Create a file “ test.sh” by using the below command

[root@linuxhelp linuxhelp]# vim test.sh
touch /home/linuxhelp/Downloads/file1.txt
mkdir /home/linuxhelp/Downloads/folder

Step 3: Grant Permission by using the below command.

[root@linuxhelp linuxhelp]# chmod u+x test.sh

Step 4: Assign a cron job and run the below command.

[root@linuxhelp]# crontab -e
45 01 18 Jun * /home/linuxhelp/Downloads/test.sh

Step 5: Change Directory by using the below command

[root@ linuxhelp]# cd /home/linuxhelp/
[root@ linuxhelp :home/linuxhelp/ ]# cd Downloads

Step 6: List the Directory at 01:45 AM by using the below command, The Scheduled job to create file and Directory will be created as shown in the below image

[root@ linuxhelp :home/linuxhelp/ cd Downloads]# ls -la

Step 7: To List the Scheduled jobs use the below command.

[root@linuxhelp]# crontab -l
45 01 18 Jun * /home/linuxhelp/Downloads/test.sh

Step 8: To Remove the Scheduled jobs use the below command.

[root@linuxhelp]# crontab -r

Conclusion:

We have reached the end of this article. In this guide, we have walked you through the steps required to Schedule a Cron Job to run Scripts in Debian 11.3. Your feedback is much welcome.

FAQ
Q
Where are crontab logs stored?
A
Logs are Stored in /var/log/cron
Q
How many cron jobs is too many?
A
The cron daemon has a limit of how many jobs it will run simultaneously. By default it is 100 jobs
Q
Can cron run multiple commands at the same time?
A
We can run several commands in the same cron job by separating them with a semi-colon (;)
Q
What is the use of * * * * * In cron?
A
It is a wildcard for every part of the cron schedule expression. So * * * * * means every minute of every hour of every day of every month and every day of the week
Q
How to Create or Edit a crontab File?
A
Create a new crontab file, or edit an existing file using the command $ crontab -e [username] .