Bird
0
0

This script is intended to rotate logs daily but fails:

medium📝 Debug Q7 of 15
Raspberry Pi - Data Logging and Databases
This script is intended to rotate logs daily but fails:
logfile="/var/log/syslog"
cp $logfile $logfile.1
> $logfile

What is the likely problem?
Acp command cannot copy files in /var/log
BThe > operator should be >> to append, not overwrite
CNot using quotes around $logfile can cause issues if path has spaces
DMissing sudo causes permission denied error
Step-by-Step Solution
Solution:
  1. Step 1: Analyze variable usage in cp and redirection

    Without quotes, if logfile path contains spaces, commands may fail or behave unexpectedly.
  2. Step 2: Check other options

    Using > to clear logfile is correct; cp works on /var/log if permissions allow; sudo may be needed but not guaranteed cause here.
  3. Final Answer:

    Not using quotes around $logfile can cause issues if path has spaces -> Option C
  4. Quick Check:

    Quote file paths to avoid errors [OK]
Quick Trick: Quote file paths in scripts to prevent errors [OK]
Common Mistakes:
MISTAKES
  • Confusing > with >> for clearing files
  • Assuming cp cannot copy system logs
  • Ignoring permission issues

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes