RHCSA RHEL 8 – Schedule tasks using at and cron

Your support on Ko-Fi is much appreciated: https://ko-fi.com/csg_yt

Buy CSG Merchandise: http://tee.pub/lic/csg

More information on Sophos Home Antivirus: http://bit.ly/SophosHP

More information about Hostinger VPS: http://bit.ly/H-VPS

This video is based on RHEL 8. Video to cover the section ‘Schedule tasks using at and cron’ for the RHCSA (Red Hat Certified System Administrator).

More information on the required learning: http://bit.ly/rhcsa8

Notes from the video:

The mentioned crontab scheduling website: https://crontab.guru/

The two services at and cron are used to schedule tasks.

at – schedule once off tasks such as reboot a server.

cron – schedule repetitive tasks such as execute a backup.

AT:

If at isn’t already installed you can install by:

# dnf install at

Check the service is started:

# systemctl status atd

If not running:

# systemctl start atd

To schedule a task to run in a minute:

# at now + 1 minute

You will then get an at> prompt to enter what you which to schedule e.g.:

at> echo “Test” > test.txt

Then enter the command and press CTRL+D to complete.

To schedule the running of a script using at use the following:

# at 3pm + 3 days -f script.sh

Of which will run the script.sh at 3pm in 3 days time.

To view the at queued jobs:

# atq

Each item will get a job number, you can remove a scheduled task by:

# atrm 4

4 being the job number.

Cron:

To edit the crontab:

# crontab -e

This will open a vi window in which you need to enter the schedule first then the the command to execute:

mm hh dm mth dw <command>

Where:

mm is minute, hh is hour, dm is day of the month, mth is the month and dw is the day of the week, use crontab.guru to help with this. Command will be script to run e.g. the backup script.

To show the contents of a the crontab without editing:

# crontab -l

To edit the crontab of another user:

# crontab -u user1 -e

To list the crontab of another user:

# crontab -u user1 -u

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Design a site like this with WordPress.com
Get started