RHCE Scripting and Task Scheduling 2 — Questions and Answers
Question 1: What does the `at` command do?
- Runs a command at a specific future time once (Correct answer)
- Schedules recurring cron jobs
- Shows process scheduling priority
- Lists currently scheduled jobs
Correct answer: Runs a command at a specific future time once
The `at` command schedules a command or script to run once at a specified future time, unlike cron which runs jobs repeatedly.
Question 2: Which command in bash reads user input and stores it in variable `NAME`?
- input NAME
- get NAME
- read NAME (Correct answer)
- scan NAME
Correct answer: read NAME
The `read` built-in command reads a line from standard input and assigns it to the specified variable.
Question 3: What does `2>&1` do in a bash command?
- Runs command in background twice
- Redirects stderr to stdout (Correct answer)
- Redirects stdout to stderr
- Duplicates the command output
Correct answer: Redirects stderr to stdout
`2>&1` redirects file descriptor 2 (stderr) to wherever file descriptor 1 (stdout) currently points.
Question 4: Which bash construct tests if a variable `$FILE` exists as a regular file?
- if [ -d $FILE ]
- if [ -f $FILE ] (Correct answer)
- if [ -e $FILE ]
- if [ -r $FILE ]
Correct answer: if [ -f $FILE ]
The `-f` test operator returns true if the specified path exists and is a regular file.
Question 5: What does the `#!/usr/bin/env bash` shebang offer over `#!/bin/bash`?
- Faster script execution
- Portability — uses the first `bash` found in PATH (Correct answer)
- Only works on RHEL
- Enables strict mode automatically
Correct answer: Portability — uses the first `bash` found in PATH
`#!/usr/bin/env bash` uses `env` to locate `bash` in the PATH, making the script more portable across systems where bash may not be at `/bin/bash`.
Question 6: Which directory stores system-wide cron jobs organized by frequency?
- /etc/cron.d/
- /var/spool/cron/
- /etc/cron.hourly/, /etc/cron.daily/, etc. (Correct answer)
- /usr/share/cron/
Correct answer: /etc/cron.hourly/, /etc/cron.daily/, etc.
Scripts placed in `/etc/cron.hourly/`, `/etc/cron.daily/`, `/etc/cron.weekly/`, and `/etc/cron.monthly/` are run at the respective intervals by `run-parts`.
What does the `at` command do?