Verify completion of scheduled jobs

Leslie is a RHEL Sysadmin at IBM:

  • His RHEL Server: RHEL_Server_0143
  • His username: leslie.robinson@ibm.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:

  1. Checking the cron log file: The cron daemon is responsible for executing scheduled jobs. Its activities are logged in the /var/log/cron file. Leslie can use the tail command 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.
  2. Listing scheduled cron jobs: Leslie can use the crontab command 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 leslie.robinson@ibm.com
    • This command will list the cron jobs configured for Leslie's user. He should replace leslie.robinson@ibm.com with his actual username.
  3. 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 pgrep command to find the process IDs (PIDs) of the running cron jobs and then verify their status using tools like ps or top.
    • pgrep cron
    • This command will provide the PIDs of all running cron processes. Leslie can then use the PID(s) with the ps command to check their status.
    • ps -p <PID>
    • Replace <PID> with the actual process ID obtained from the previous command.
  4. 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 /path/to/output.log. The 2>&1 redirects any error output to the same file.
    • Leslie can then check the contents of the output file using tools like cat or less:
    • 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.

You should also read:

Understand Jobs and CronJobs

Jonah is a RHEL Sysadmin at Google. He is studying for his CKAD exam, specifically this objective: Understand Jobs and CronJobs. Please generate…