Explore the fundamentals of cron jobs and task scheduling in Linux, covering syntax, scheduling expressions, common commands, and error handling. This quiz is designed to assess your understanding of automated command execution and maintenance strategies within the Linux tools ecosystem.
Which of the following crontab entries would run a script every day at 5:30 AM?
Explanation: The cron timing '30 5 * * *' specifies the command should run at 5:30 each day. '5 30 * * *' would run at 30 minutes past 5 o’clock, which is not valid due to the reversed minute and hour fields. '30 17 * * *' runs at 5:30 PM, not AM. '5 30 0 0 *' includes non-existent date/month values, making it invalid syntax.
If a script scheduled by cron fails due to 'command not found', what is the most likely reason related to cron's environment?
Explanation: Cron jobs run in a minimal environment, often with a very restricted PATH, causing 'command not found' errors if commands are not specified with full paths. Locking the script file is unrelated to command availability. High CPU usage doesn't typically cause 'command not found' directly. Lack of execute permissions would result in a 'Permission denied' error, not 'command not found'.
Which cron expression schedules a job to run every 15 minutes, regardless of hour and day?
Explanation: The '*/15' in the minute field means every 15 minutes, while '*' in subsequent fields means every hour, day, and month, thus meeting the requirement. '0 0 * * 15' schedules at midnight on the 15th of every month. '15 * * * 0' means at the 15th minute of every Sunday. '* 15 * * *' is every minute during the 15th hour of each day.
Which command allows a user to list their current cron jobs?
Explanation: 'crontab -l' lists the current user's cron jobs. 'cronjob --list' and 'cron -list' are not standard or valid commands in Linux. 'crontab --edit' is an incorrect form; the correct command for editing is 'crontab -e'.
What is a recommended way to ensure you are notified of errors when your cron job fails or outputs something unexpected?
Explanation: Setting the MAILTO variable in your crontab directs any job output to the specified email, alerting you to failures or unexpected messages. 'cron --verbose' is not an applicable command. Setting random environment variables does not help with notifications. Scheduling jobs outside working hours does not inform you about errors—it only changes the job timing.