0
0
Bash Scriptingscripting~20 mins

Logging framework in Bash Scripting - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Logging Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
1:30remaining
What is the output of this logging command?
Consider this bash script snippet that uses a simple logging function:
log() {
  level=$1
  message=$2
  echo "[$(date +'%Y-%m-%d %H:%M:%S')] $level: $message"
}

log "INFO" "Deployment started"

What will be the output format of the last command?
Bash Scripting
log() {
  level=$1
  message=$2
  echo "[$(date +'%Y-%m-%d %H:%M:%S')] $level: $message"
}

log "INFO" "Deployment started"
A[YYYY-MM-DD HH:MM:SS] INFO: Deployment started
B[INFO] YYYY-MM-DD HH:MM:SS Deployment started
CINFO [YYYY-MM-DD HH:MM:SS]: Deployment started
DDeployment started INFO [YYYY-MM-DD HH:MM:SS]
Attempts:
2 left
💡 Hint
Look at how the echo command formats the output string with date and level.
Configuration
intermediate
1:30remaining
Which syslog configuration line sets the log level to 'warning' for a service?
In the syslog configuration file, you want to log only warnings and errors from the 'auth' facility. Which line correctly configures this?
Aauth.error /var/log/auth.log
Bauth.debug /var/log/auth.log
Cauth.warning /var/log/auth.log
Dauth.info /var/log/auth.log
Attempts:
2 left
💡 Hint
The log level 'warning' includes warnings and errors but excludes info and debug.
Troubleshoot
advanced
2:00remaining
Why does this bash logging function fail to log multi-word messages correctly?
Given this function:
log() {
  echo "[$(date)] $1: $2"
}

log INFO Deployment started successfully

Why does the output only show 'Deployment' instead of the full message?
Bash Scripting
log() {
  echo "[$(date)] $1: $2"
}

log INFO Deployment started successfully
ABecause $2 only captures the second word; the rest are ignored without quotes.
BBecause date command is missing format specifier.
CBecause echo does not support multiple arguments.
DBecause the function is missing a return statement.
Attempts:
2 left
💡 Hint
Think about how bash handles positional parameters and multiple words.
🔀 Workflow
advanced
2:30remaining
What is the correct order to set up a centralized logging system using rsyslog?
Arrange these steps in the correct order to configure a centralized logging server with rsyslog:
1. Configure clients to send logs to the server
2. Install rsyslog on server and clients
3. Configure server to receive remote logs
4. Restart rsyslog service on all machines
A2,1,3,4
B1,2,3,4
C1,3,2,4
D2,3,1,4
Attempts:
2 left
💡 Hint
You must install software before configuring it, and server config before client config.
Best Practice
expert
3:00remaining
Which logging practice helps avoid losing logs during high load in a bash script?
You have a bash script that logs messages to a file. Sometimes under heavy load, logs are lost or incomplete. Which practice best prevents this?
AWrite logs to a variable and echo all at the end of the script
BUse a logging function that appends logs with '>>' and flushes output immediately
CUse 'echo' without redirection and rely on stdout capture
DWrite logs to /dev/null to avoid disk I/O delays
Attempts:
2 left
💡 Hint
Think about how to ensure logs are written safely and immediately to disk.