Schedule tasks to run at a set date and time
Charlie Parker is a saxophone virtuoso by day, and a RHEL Sysadmin at Red Hat by night (he works the midnight to 8 AM shift 5 days a week). During his breaks at work, he sneaks in practicing a few choruses of "Cherokee" on his alto sax. He finds out from his supervisor that he has to train two new interns: John Coltrane and Jackie McLean. Coincidentally, both men play the saxophone at a very high level as well.
This morning, Charlie schooled John and Jackie during an early morning jam session at the C. Grace jazz club; now he has to school them on this topic: scheduling tasks to run at a set date and time.
Charlie administers the RHEL server Saxophone_Goats_RHEL_server_01. His username is charlie.bird.parker. He has created accounts for his interns on his server as well: john.coltrane and jackie.mclean. Charlie Parker is a genius with an IQ so high that it is difficult to measure using traditional methods, so he NEVER runs commands as the root user. Charlie Parker's mind works so fast that it is impossible for a computer to generate problems as fast as he can, but please try: please generate several problems and solutions that Charles can use to get John and Jackie up to speed on the task of scheduling tasks on a RHEL server.
Sure! Here are some problems and solutions that Charlie can use to train John Coltrane and Jackie McLean on scheduling tasks on a RHEL server:
Problem 1: John wants to schedule a backup task to run every Sunday at 2 AM. How can he achieve this?
Solution 1: John can use the
crontab command to schedule the backup task. He can open his user's crontab file by running the command
crontab -e and then add the following line to schedule the task:
0 2 * * 0 /path/to/backup_script.sh
This schedule expression
0 2 * * 0 means "At 2 AM every Sunday." He should replace
/path/to/backup_script.sh with the actual path to his backup script.
Problem 2: Jackie needs to schedule a system reboot on the 1st of every month at 3 AM. How can he accomplish this?
Solution 2: Jackie can use the
crontab command to schedule the system reboot task. She should run
crontab -e to open her user's crontab file and add the following line:
0 3 1 * * /sbin/shutdown -r now
In this case, the schedule expression
0 3 1 * * means "At 3 AM on the 1st day of every month." The command
/sbin/shutdown -r now will initiate the system reboot.
Problem 3: Charlie wants to schedule a task to run every weekday at 7 PM except for Fridays. How can he set up this schedule?
Solution 3: Charlie can use the
crontab command to schedule the task excluding Fridays. He should run
crontab -e and add the following line:
0 19 * * 1-4,6 /path/to/task_script.sh
The schedule expression
0 19 * * 1-4,6 means "At 7 PM on Monday to Thursday and Saturday." Fridays are excluded from the schedule. He should replace
/path/to/task_script.sh with the actual path to his task script.
These are just a few examples of scheduling tasks on a RHEL server using
crontab. Charlie can use these problems and solutions to guide John and Jackie in understanding how to schedule tasks at specific dates and times.