What's new

Welcome to Ruzgar.com

Join us now to get access to all our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, and so, so much more. It's also quick and totally free, so what are you waiting for?

Ask question

Ask questions and get answers from our community


Answer questions and become an expert on your topic

Contact us

Contact the site administrator directly.


Just like Facebook join them and enjoy.

Centos Lesson 9 Scheduled tasks with CRON


Staff member
Oct 3, 2021
Reaction score
Some operations may need to be performed repeatedly automatically. In this case CRON is used in linux. For example, regular update check, regular update, regular backup, regular file scanning are done with CRON.
CRONs are set in minutes, hours, days, months and business days. CRONs are saved in the Crontab file. These transactions are controlled by the Crond process on a minute-by-minute basis.

For the Cron service to run on Centos, the vixie-cron RPM package must be installed. You can run the following code to check:

rpm -q vixie-cron

If you are using cPanel or Directadmin, it is normal to get a file not found error. To check the Cron status on your system.
You can type
service crond status
You can see the scheduled crons with the command
crontab -l
You can change the cron file with the
crontab -e

When we open the cron file with the cat /etc/crontab command, we see an example Cron.

* minute: It is the minute information. It can take values from 0 to 59.
* hour: Reports the time. It can take values between 0 and 24.
* day of month: It can take values from 1 to 31. Indicates which day of the month the cron will run.
* month: Indicates the month in the year. It can take values between 1 and 12.
* day of week: takes a value between 0 and 7. Sunday is the first day, its value is 0 (could be 7) Monday is 1. Tuesday is 2. Wednesday is 3. Thursday is 4, Friday is 5. Saturday is 6 pm. sun,mon,tue,wed,thu,fri,sat values can also be entered.
command: the main task is written here.


CRON Examples:

* * * * * ping -c 5
With this code, we send 5 packets to ip every minute.
* 02 15 * 1 cp /home/error.log /ruzgar/com
With this code, it will copy the error.log file in the home folder to the com directory in the ruzgar folder on every Monday and every 15th at 2 am. ..
00 02-10 * * * service ruzgar restart
With this code (00 means every hour), ruzgar service is restarted at 1 hour intervals between 2 am and 10 am.
00 02-10 * * 2-4 service ruzgar restart
With this code, ruzgar service will be restarted on Tuesdays and Thursdays between 2 am and 10 am.
* /30 * * * tail -4 /etc/var/maillog >> /root/ruzgar/kayit.txt
With this code, the last 4 lines of 1 maillog file in every half hour are the record in ruzgar. txt file will be printed.
04 19 * * 3 rsync -av /home/ /yedek/ruzgar
With this code, every Wednesday at 19:04 the home file will be thrown into the ruzgar file as a backup.

Custom CRON values:

@reboot : Occurs every time the operating system reboots.
@hourly: it happens hourly.
@daily: It happens once a day.
@midnight: It happens every midnight.
@weekly: It happens 1 more per week.
@monthly: it happens once a month.
@annually: It happens once a year.
@yearly: It happens once a year.

It is used as follows:

@monthly cp apple.txt pear.txt
With this command, the contents of the apple.txt file every month are written into the pear.txt file.