Site icon Database Tutorials

How To Create Crontab Job On Linux

What is Crontab?

If you want to perform regular operations(for example schedule a task) on Linux, you should create a cron job.

Create a Crontab Job

To create a Crontab Job, we first connect to the server as root.

Then run the below command and press the insert key from the keyboard.

Finally, we create the job by pasting the following line.

On the above line, the sh command after “00 09 * * *” indicates that we will run an sh file.

The command below specifies that the diskusage.sh file in the “xx / postgres_scripts” directory will work.

let’s enumerate the parameters in the above line and look at meaning of each number.

1 It specifies the minute the job will work(0-59)
2 It specifies the hour the job will work(0-23)
3 It specifies the day the job will work(1-31)
4 It specifies the month the job will work(1-12)
5 It specifies what day of the week the job will work.(0-7) Sunday=0 or 7

Let’s make some examples.

Example1:

If you add the above line to crontab, diskusage.sh runs every year on the 12th month, 7th day, at 16:30.

Crontab job to run every minutes

If you add the above line to crontab, diskusage.sh runs every minutes..

Cron job to run every 5 minutes

If you add the above line to crontab, diskusage.sh runs every 5 minutes..

Cron job to run every 10 minutes

If you add the above line to crontab, diskusage.sh runs every 10 minutes..

Cron job to run every 15 minutes

If you add the above line to crontab, diskusage.sh runs every 15 minutes..

Cron job to run every 30 minutes

If you add the above line to crontab, diskusage.sh runs every 30 minutes..

Cron job to run every hour

If you add the above line to crontab, diskusage.sh runs ever hour at minute 0..

Cron job to run every 2 hours

If you add the above line to crontab, diskusage.sh runs every 2 hours..

Cron job to run every 3 hours

If you add the above line to crontab, diskusage.sh runs every 3 hours..

Cron job to run every day

If you add the above line to crontab, diskusage.sh runs every year, every month, every day at 16:30.

Cron job to run every week on Sunday

If you add the above line to crontab, diskusage.sh runs every year, every month, every week on Sunday at 00:00.

Cron job to run on weekdays

If you add the above line to crontab, diskusage.sh runs on weekday.(Monday,Tuesday,Wednesday,Thursday and Friday at 00:00).

Cron job to run on weekend

If you add the above line to crontab, diskusage.sh runs on weekend.(Saturday and Sunday at 00:00).

Cron job to run every month

If you add the above line to crontab, diskusage.sh runs every month.(At 00:00 on day-of-month 1).

Cron job to run every year

If you add the above line to crontab, diskusage.sh runs every year.(At 00:00 on day-of-month 1 in January.)

Cron job run on specific day

If you add the above line crontab, diskusage.sh runs every year, every month, every week on Saturday at 16:30.

Cron job to run on last day of month

If you add the above line to crontab, diskusage.sh runs on last day of month at 23:59)

Cron job to run first day of month

If you add the above line to crontab, diskusage.sh runs on first day of month at 00:00)

Exit mobile version