RHCE Scripting and Task Scheduling 1 — Questions and Answers
Question 1: Which shebang line is correct for a bash script on RHEL?
- #/bin/bash
- #!/bin/bash (Correct answer)
- # !/usr/bin/bash
- //bin/bash
Correct answer: #!/bin/bash
`#!/bin/bash` is the correct shebang that tells the kernel to use `/bin/bash` as the interpreter for the script.
Question 2: What does the `$?` variable represent in a bash script?
- Current script's PID
- Number of arguments passed
- Exit code of the last command (Correct answer)
- Current user's UID
Correct answer: Exit code of the last command
`$?` holds the exit status of the most recently executed foreground command (0 = success, non-zero = failure).
Question 3: Which `cron` field position represents 'day of the week'?
- 4th field
- 5th field (Correct answer)
- 3rd field
- 6th field
Correct answer: 5th field
In cron syntax, the fields are: minute, hour, day-of-month, month, day-of-week — making day-of-week the 5th field.
Question 4: What command lists all cron jobs for the current user?
- crontab -e
- crontab -l (Correct answer)
- cron -list
- cat /etc/crontab
Correct answer: crontab -l
`crontab -l` lists (displays) the current user's crontab without editing it.
Question 5: Which special cron string runs a job every day at midnight?
- @midnight
- @daily
- 0 0 * * *
- All of the above (Correct answer)
Correct answer: All of the above
`@midnight`, `@daily`, and `0 0 * * *` are all valid cron expressions that schedule a job to run at midnight every day.
Question 6: What is the purpose of `systemd.timer` units in RHEL?
- Set system clock time zones
- Schedule tasks as a modern cron replacement using systemd (Correct answer)
- Manage service startup delays
- Track service uptime
Correct answer: Schedule tasks as a modern cron replacement using systemd
Systemd timer units provide a modern alternative to cron for scheduling tasks, with better integration into systemd logging and dependency management.
Which shebang line is correct for a bash script on RHEL?