Automate Administrative Tasks in Linux Using Cron and Scripting
This Automate Administrative Tasks in Linux Using Cron, and Scripting IT Pro Challenge helps learners understand how to review a backup script, use the cron service to schedule a script to run, and review a script that can gather server information.
In this Automate Administrative Tasks in Linux Using Cron and Scripting IT Pro Challenge, learners will understand how to review and copy a backup script, use the cron daemon and the at command to schedule a script to run at a defined time, and execute a script that can gather system information at a scheduled time at set intervals. Learners will also understand the difference between cron and systemd-time. The skills learned in this lab are helpful for anyone who wants to be a Linux system administrator.
For this virtual lab, the scenario is that you are the Linux system administrator, and your company needs you to automate some administrative tasks. To accomplish your goal, you will first need to review the existing backup script and then use the cron daemon (crond) to schedule that script to execute at defined times. Then you will review an additional script that collects system information and schedule that script to run at a specific time.
There is no cron command; crond is a system-managed executable that allows you to schedule tasks. The crontab command allows you to initiate the cron service (cron table). The crontab file is a text file that tells crond to perform a task at a specified time or interval. All users on the system (including the root user) can create a cron task because it runs with the user’s account permissions.
Copy and review the backup script
To begin, you need to review the existing backup script and create a storage location for the backup file. Run the backup script to make sure it executes as expected. Then you will copy a second script to the local user directory. You will use this second script later in the lab.
Schedule a script using the at command and the cron service
Next, you will use the at command to schedule the backup script to run at a specified time. Then you will use the atq command to verify that the task is scheduled. Then you will use crontab to schedule a script to run at a specified time at a designated interval and verify that the task has been scheduled by viewing the cron list.
NOTE: The at command is used for tasks that you only need to execute once. The atq command is used to list all of the pending user-scheduled jobs.
Copy and review a script to gather information about the server
Review the script that you copied to the user directory in the first step. This script is designed to gather system information like date, users on the system, available storage, etc. You will then run the script, save the results to a file, and confirm that the script executed as expected.
Schedule the ServerStatsScript.sh script by using the systemd-timer command
While cron is used for scheduling timed tasks, systemd-timer can do that and more. With systemd-timer, you can also schedule time tasks, as well as automatically generate logs, set CPU usage, and more.
In this last step of the lab, you will create a service configuration file and configure the file to run a script. Then create a systemd-timer file to execute the configuration file. Then you will enable the timer and confirm that the timer is scheduled to be executed.
By taking this virtual lab, you will learn how to review and copy a backup script, use the at command and the crond to schedule the backup script to run, create a system information gathering script, and run that script using the systemd-timer.
Our self-paced online CompTIA Linux+ course prepares students with the knowledge to become a certified ...
Regularly scheduled system backups are vital to maintaining users' data. Manual backups are prone ...