Bird
Raised Fist0
Bash Scriptingscripting~20 mins

Why sysadmin scripts automate operations in Bash Scripting - Challenge Your Understanding

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Sysadmin Automation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Why do sysadmin scripts automate repetitive tasks?
Which of the following is the main reason sysadmin scripts automate repetitive tasks?
ATo reduce human errors and save time by automating routine operations
BTo make the system run slower for testing purposes
CTo increase the number of manual steps required
DTo make the system less secure by adding more scripts
Attempts:
2 left
💡 Hint
Think about what happens when humans repeat the same task many times.
🧠 Conceptual
intermediate
1:30remaining
What is a key benefit of automating system updates with scripts?
Why do sysadmins use scripts to automate system updates?
ATo make updates optional and random
BTo slow down the update process intentionally
CTo prevent updates from ever being installed
DTo ensure updates are applied consistently and on schedule without manual intervention
Attempts:
2 left
💡 Hint
Think about how automation helps keep systems secure and up to date.
💻 Command Output
advanced
2:00remaining
Output of a script automating user creation
What is the output of this bash script that automates adding a user named 'alice'?
Bash Scripting
#!/bin/bash
username=alice
if id "$username" &>/dev/null; then
  echo "User $username already exists"
else
  sudo useradd "$username" && echo "User $username created"
fi
ASyntax error: unexpected token
BUser alice already exists
CUser alice created
DPermission denied error
Attempts:
2 left
💡 Hint
Assume the user 'alice' does not exist and the script runs with proper permissions.
🔧 Debug
advanced
2:00remaining
Identify the error in this automation script snippet
What error will this bash script produce when automating file backup? code: #!/bin/bash backup_dir=/backup file_to_backup=/etc/passwd cp $file_to_backup $backup_dir
Acp: missing destination file operand after '/backup'
BNo error, backup succeeds
Ccp: cannot stat '/etc/passwd': No such file or directory
Dcp: cannot create regular file '/backup': Is a directory
Attempts:
2 left
💡 Hint
Check how the cp command is used with directories and files.
🚀 Application
expert
2:30remaining
How does automating log rotation improve system management?
Which of the following best explains how automating log rotation benefits system administrators?
AIt prevents log files from growing too large, saving disk space and keeping logs manageable
BIt disables logging to improve system speed
CIt merges all logs into one huge file for easier reading
DIt deletes all logs immediately after creation to save space
Attempts:
2 left
💡 Hint
Think about what happens if logs grow without limits.

Practice

(1/5)
1. Why do sysadmins use scripts to automate operations?
easy
A. To save time by automating repetitive tasks
B. To make the system slower
C. To increase manual work
D. To avoid using computers

Solution

  1. Step 1: Understand the purpose of automation

    Automation helps reduce repetitive manual work by letting scripts do the tasks.
  2. Step 2: Identify the benefit for sysadmins

    Saving time and effort is the main reason sysadmins automate operations.
  3. Final Answer:

    To save time by automating repetitive tasks -> Option A
  4. Quick Check:

    Automation saves time = C [OK]
Hint: Automation means less manual work, more saved time [OK]
Common Mistakes:
  • Thinking automation slows systems
  • Believing automation increases manual work
  • Confusing automation with avoiding computers
2. Which of these is the correct way to start a bash script for automation?
easy
A. function main() {}
B. print('Hello World')
C. #!/bin/bash
D.

Solution

  1. Step 1: Identify the bash script shebang

    The line #!/bin/bash tells the system to use bash to run the script.
  2. Step 2: Check other options for language mismatch

    Options A, B, and C are for other languages, not bash.
  3. Final Answer:

    #!/bin/bash -> Option C
  4. Quick Check:

    Shebang for bash = D [OK]
Hint: Bash scripts start with #!/bin/bash line [OK]
Common Mistakes:
  • Using Python or JavaScript syntax in bash scripts
  • Omitting the shebang line
  • Confusing script languages
3. What will this script output?
#!/bin/bash
count=0
for file in /tmp/*; do
  if [ -f "$file" ]; then
    ((count++))
  fi
done
echo $count
medium
A. Number of files in /tmp directory
B. List of all files in /tmp
C. Error message about syntax
D. Zero always

Solution

  1. Step 1: Understand the loop and condition

    The script loops over all items in /tmp, checks if each is a file, and counts them.
  2. Step 2: Determine the output

    It prints the total count of files found in /tmp, not the list or zero.
  3. Final Answer:

    Number of files in /tmp directory -> Option A
  4. Quick Check:

    Count files in /tmp = A [OK]
Hint: Count files by looping and incrementing count [OK]
Common Mistakes:
  • Thinking it lists files instead of counting
  • Assuming syntax error due to ((count++))
  • Believing output is always zero
4. Find the error in this script snippet that aims to backup a file:
#!/bin/bash
file="/etc/passwd"
cp $file /backup/
if [ $? -eq 0 ]; then
  echo "Backup successful"
else
  echo "Backup failed"
fi
medium
A. The variable file is not defined correctly
B. The /backup directory may not exist, causing cp to fail
C. The if condition syntax is wrong
D. The echo commands are missing quotes

Solution

  1. Step 1: Check the copy command and target directory

    The script copies /etc/passwd to /backup/. If /backup/ does not exist, cp will fail.
  2. Step 2: Verify other parts for correctness

    Variable is defined correctly, if syntax is valid, and echo quotes are optional but fine.
  3. Final Answer:

    The /backup directory may not exist, causing cp to fail -> Option B
  4. Quick Check:

    Missing target directory causes failure = B [OK]
Hint: Ensure target directories exist before copying files [OK]
Common Mistakes:
  • Assuming variable is wrong
  • Thinking if syntax is incorrect
  • Believing echo needs quotes always
5. A sysadmin wants to automate checking disk space and send an alert if usage exceeds 80%. Which script snippet correctly automates this?
hard
A. usage=$(df / | tail -1 | awk '{print $5}') if [ $usage -eq 80 ]; then echo "Disk usage is exactly 80%" fi
B. usage=$(df / | head -1 | awk '{print $5}') if [ $usage -lt 80 ]; then echo "Disk usage is low" fi
C. usage=$(df / | tail -1 | awk '{print $4}') if [ $usage -gt 80 ]; then echo "Alert: Disk usage high" fi
D. usage=$(df / | tail -1 | awk '{print $5}' | sed 's/%//') if [ $usage -gt 80 ]; then echo "Alert: Disk usage is above 80%" fi

Solution

  1. Step 1: Extract disk usage percentage correctly

    The command extracts the 5th column from df output (like '85%'), then removes the '%' sign to get a number.
  2. Step 2: Check the condition for usage above 80%

    The script compares usage number to 80 and alerts if greater, matching the requirement.
  3. Final Answer:

    usage=$(df / | tail -1 | awk '{print $5}' | sed 's/%//') if [ $usage -gt 80 ]; then echo "Alert: Disk usage is above 80%" fi -> Option D
  4. Quick Check:

    Extract usage and alert if >80% = A [OK]
Hint: Remove % sign before numeric comparison [OK]
Common Mistakes:
  • Comparing strings with % sign included
  • Using wrong df column for usage
  • Checking for exact 80% instead of greater
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard