RHCSA RHCSA Shell Scripting and Automation 2 — Questions and Answers
Question 1: Which cron field order is correct when defining a cron job?
- minute hour day month weekday (Correct answer)
- hour minute day month weekday
- day month minute hour weekday
- weekday month day hour minute
Correct answer: minute hour day month weekday
The standard cron field order is: minute (0–59), hour (0–23), day of month (1–31), month (1–12), day of week (0–7).
Question 2: What cron schedule expression runs a job every day at 2:30 AM?
- 30 2 * * * (Correct answer)
- 2 30 * * *
- * * 2 30 *
- 30 * 2 * *
Correct answer: 30 2 * * *
The expression `30 2 * * *` means minute=30, hour=2, any day, any month, any weekday — i.e., 2:30 AM daily.
Question 3: Which command lists all cron jobs for the current user?
- crontab -l (Correct answer)
- crontab -e
- crontab -r
- crontab -v
Correct answer: crontab -l
`crontab -l` lists the current user's scheduled cron jobs without opening an editor.
Question 4: In a Bash `if` statement, which operator tests if two strings are equal?
- == (Correct answer)
- =~
- -eq
- !=
Correct answer: ==
Inside `[[ ]]` or `[ ]`, the `==` operator performs string equality comparison in Bash.
Question 5: What does the `read` command do in a Bash script?
- Reads input from stdin into a variable (Correct answer)
- Reads a file line by line
- Outputs a variable value
- Reads environment variables
Correct answer: Reads input from stdin into a variable
The `read` command reads a line from standard input and stores it in the specified variable name.
Question 6: Which special variable in Bash holds the PID of the last background process?
- $! (Correct answer)
- $?
- $$
- $-
Correct answer: $!
`$!` expands to the process ID of the most recently executed background pipeline or command.
Which cron field order is correct when defining a cron job?