Last updated
Last updated
Cron is a daemon that triggers jobs on a specific time, the cron is mostly used for regular re-occurring jobs, systemd timer is the new alternative for cron. Scripts are executed on an hourly,daily,weekly,monthly basis. You can find all the generic time-specific cron jobs within /etc/cron.d Lemme show you how to schedule a job using cron : -> crontab -e or we can create a file under /etc/cron.d/ -> Then, we will have to define the job, take a quick view on /etc/crontab if you forget the format. -> verify using crontab -l -> crontab -r if you wish to clear the crontab task. -> a file is created under /var/spool/cron for each user. Below, I will show you some jobs created with cron :
You can use "@" as shortcut if you are scheduling a job hourly-daily...etc Cron does not have STDOUT, Hence, you can't use echo, instead you can use logger. Consult man 5 crontab for more information.
anacron is the service behind cron to execute a cron job on a regular basis, but not in a specific time. it can be used to control the execution of daily, weekly and monthly jobs or anything with period of n day. You can find the configuration file under /etc/anacrontab. Let me show you a quick example :
used for jobs that need to be started once. atd is the service behind running the once-started jobs.
Now lets see how at works : -> at <time> example : at 3pm today
-> task example : echo " Hello World" > /root/example.txt
-> CTRL+D
-> to save and quit the interface.
-> atq -> to list the pending jobs
-> atrm <job_nb> -> to remove a scheduled
Learn how to schedule tasks and job in RHEL8.