0
0
Bash Scriptingscripting~10 mins

Logging framework in Bash Scripting - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to write a log message to a file.

Bash Scripting
echo "Starting process..." >> [1]
Drag options to blanks, or click blank then click option'
A/var/log/process.log
B/etc/passwd
C/home/user/document.txt
D/tmp/randomfile
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-log file path for logging.
Overwriting the log file instead of appending.
2fill in blank
medium

Complete the code to log an error message with a timestamp.

Bash Scripting
echo "$(date) ERROR: Disk space low" >> [1]
Drag options to blanks, or click blank then click option'
A/var/log/syslog
B/var/log/error.log
C/var/log/auth.log
D/var/log/wtmp
Attempts:
3 left
💡 Hint
Common Mistakes
Logging errors to unrelated log files.
Not including a timestamp in the log message.
3fill in blank
hard

Fix the error in the code to correctly log a warning message.

Bash Scripting
echo "WARNING: Low memory" [1] /var/log/warnings.log
Drag options to blanks, or click blank then click option'
A|
B>
C>>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using single > which overwrites the log file.
Using pipe or input redirection symbols incorrectly.
4fill in blank
hard

Fill both blanks to create a function that logs messages with levels.

Bash Scripting
log_message() {
  echo "$(date) [1]: $1" [2] /var/log/app.log
}
Drag options to blanks, or click blank then click option'
AINFO
B>>
C>
DDEBUG
Attempts:
3 left
💡 Hint
Common Mistakes
Using > which overwrites the log file.
Using an incorrect log level or missing it.
5fill in blank
hard

Fill all three blanks to create a log entry with dynamic level and message.

Bash Scripting
log() {
  level=[1]
  message=[2]
  echo "$(date) $level: $message" [3] /var/log/custom.log
}
Drag options to blanks, or click blank then click option'
A"$1"
B"$2"
C>>
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using > which overwrites the log file.
Not quoting the parameters properly.