Leslie is a RHEL Sysadmin at IBM:
- His RHEL Server: RHEL_Server_0143
- His username: email@example.com
- His professional preference: experienced RHEL engineers NEVER run commands as the root user
- His certifications: he's studying to pass the LFCS exam
- Task: Verify completion of scheduled jobs
Leslie is mastering the RHEL LFCS exam objective of verifying the completion of scheduled jobs. Please teach him how to do so by generating and explaining several command examples that will teach him how to master this objective.
To verify the completion of scheduled jobs on a RHEL (Red Hat Enterprise Linux) server, Leslie can use various commands and techniques. Here are some examples that will help him master this objective:
- Checking the cron log file: The cron daemon is responsible for executing scheduled jobs. Its activities are logged in the
/var/log/cronfile. Leslie can use the
tailcommand to view the last few lines of the log file and check for any recent job completions.
- sudo tail /var/log/cron
- This command will display the last 10 lines of the cron log file. If there are any errors or output generated by scheduled jobs, he will be able to see them here.
- Listing scheduled cron jobs: Leslie can use the
crontabcommand to list the scheduled cron jobs for a specific user. This will show him the commands and their schedule set for execution.
- crontab -l -u firstname.lastname@example.org
- This command will list the cron jobs configured for Leslie's user. He should replace
email@example.com his actual username.
- Checking the status of running cron jobs: Sometimes, long-running cron jobs may still be executing when Leslie checks for their completion. In such cases, he can use the
pgrepcommand to find the process IDs (PIDs) of the running cron jobs and then verify their status using tools like
- pgrep cron
- This command will provide the PIDs of all running cron processes. Leslie can then use the PID(s) with the
pscommand to check their status.
- ps -p <PID>
<PID>with the actual process ID obtained from the previous command.
- Logging output of scheduled jobs: By default, the output of scheduled jobs executed via cron is sent to the user's email. However, Leslie can redirect the output to a file for easier monitoring. To do this, he can modify the cron job commands to include output redirection.
- 0 0 * * * /path/to/command >> /path/to/output.log 2>&1
- In this example, the output of the command executed at midnight (0 0 * * *) is redirected to
2>&1redirects any error output to the same file.
- Leslie can then check the contents of the output file using tools like
- cat /path/to/output.log
These are some of the command examples that Leslie can use to verify the completion of scheduled jobs on his RHEL server. It's important to note that some of these commands may require root or elevated privileges, so he should use
sudo where necessary.