Courseiva
Create simple shell scriptseasyMultiple ChoiceObjective-mapped

EX200 Create simple shell scripts Practice Question

A developer wrote a shell script that is intended to back up log files by copying all .log files from /var/log/myapp to /backup/logs. The script runs daily via cron but the backup folder is empty. The script contains the following line: `cp /var/log/myapp/*.log /backup/logs/`. What is the most likely reason the backup fails?

⚠ Common exam trap

Red Hat often tests the misconception that cron PATH or permissions are the root cause, but the real trap is that glob expansion happens at script execution time and an empty glob silently fails, leading to an empty backup destination.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

No .log files exist in /var/log/myapp at the time of script execution, causing the glob to match nothing.

The glob pattern `*.log` in the `cp` command is expanded by the shell at the time the script runs. If no `.log` files exist in `/var/log/myapp` when the cron job executes, the shell passes the literal string `*.log` to `cp`, which then fails with a 'No such file or directory' error (or, depending on shell settings, may silently do nothing). This is a common issue when log rotation or cleanup removes files before the backup runs.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • The PATH variable in cron is not set, so cp cannot be found.

    Why it's wrong here

    The default PATH in cron is minimal but typically includes /usr/bin:/bin, where cp is installed by default on Red Hat systems. A script executed by cron therefore locates cp without requiring any special PATH modification. Moreover, a backup script could safely call /bin/cp with an absolute path, so this cannot be the reason the backup is not created.

  • The script does not have execute permission for the user running cron.

    Why it's wrong here

    Cron does not require a script file to be executable if the crontab entry invokes an interpreter explicitly, such as /bin/bash /path/to/script, which is a common and robust pattern. Since the question states that the script is already running daily via cron, a missing execute bit would prevent it from running at all, not just make the backup fail. The real problem must occur after the script starts executing.

  • No .log files exist in /var/log/myapp at the time of script execution, causing the glob to match nothing.

    Why this is correct

    In a non-interactive shell, an unmatched glob like /var/log/myapp/*.log is not expanded and is passed literally to cp. cp then attempts to copy a file named `*.log`, which does not exist, producing a 'No such file or directory' error and creating no backup. Unless the script checks the glob result or has error handling, this failure can be silent, especially if cron's stderr output is not inspected.

  • The cron job is not enabled because the crontab syntax is incorrect.

    Why it's wrong here

    If the crontab syntax were invalid, crond would log a parse error and would not install the job, so the script would never run. The question explicitly says the script runs daily, which confirms the crontab entry is valid and enabled. An invalid crontab could not be the cause of a missing backup when the job is demonstrably executing.

About these practice questions

This EX200 question is part of Courseiva's 127-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This EX200 practice question is part of Courseiva's free Red Hat certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the EX200 exam.