Linux and Command-Line Basics

The line "30 2 * * 1 /home/alice/backup.sh" was registered in cron. Which of the following is when backup.sh is run?

  1. AAt 2:30 on the 1st of every month
  2. BAt 2:30 every Monday
  3. CAt 2:30 every Sunday
Show answer and explanation

Answer: B. At 2:30 every Monday

In a cron configuration (crontab), each line starts with five fields that are, from the left, "minute, hour, day of month, month, day of week", followed by the command to run. In this line the minute is 30, the hour 2, the day of month and month * (every), and the day of week 1, so it runs at 2:30 every Monday. For the day of week, 0 is Sunday and 1 is Monday, and in many implementations 7 also means Sunday. Commands run from cron work with a limited set of environment variables, unlike a login session, so care is needed, such as writing commands in scripts with absolute paths.

  • A. For the 1st of every month, set the third field, the day of month, to 1, as in "30 2 1 * *". The fifth field is the day of week.
  • B. Correct. It means minute 30, hour 2 and day of week 1 (Monday).
  • C. In the day-of-week field, 0 (or 7) is Sunday and 1 is Monday.
Practice this topic Back to topic

Books on Linux and Command-Line Basics Ad

As an Amazon Associate I earn from qualifying purchases.

More Linux and Command-Line Basics questions

  1. A Linux server warns that disk space is running low. Which of the following is the correct pair of a command to check usage and free space for each file system and a command to total the space used by the files in a directory?
  2. You created a public-key authentication key pair with ssh-keygen on your own PC and want to connect to the server server1 with ssh without a password. Which of the following is the correct way to place the keys?
  3. Which of the following is what happens when "tar -czf proj.tar.gz proj/" is run?
  4. After editing main.c, a file managed with Git, only git commit -m "fix" was run, and "no changes added to commit" was shown and nothing was committed. Which of the following is the reason?
  5. You ran git commit in Git, but the commit does not yet appear in the GitHub repository shared by the team. Which of the following is the reason?