Module 3 - Bash scripting

Lab 1: System Health Check Script

  • How do you write a script (system_health.sh) that checks CPU, memory, and disk usage?

  • How do you log the output to /var/log/sys-health.log?

  • How do you make the script print “System Healthy” when all values are under 80%?


Lab 2: Log File Analyzer

  • How do you write a script (log_analyzer.sh) that reads /var/log/syslog?

  • How do you print the top 10 most repeated error messages?

  • How do you save the results to log_report.txt?


Lab 3: Backup Automation Script

  • How do you write a script (backup.sh) that compresses a directory into a .tar.gz file?

  • How do you store the backup in /backup/ with a timestamp?

  • How do you delete backups older than 7 days?


Lab 4: User Management Script

  • How do you write a script (create_user.sh) that accepts a username as input?

  • How do you create the user and the group devops if it does not exist?

  • How do you add the user to the devops group?

  • How do you force the user to change their password on first login?


Lab 5: Process Monitoring Script

  • How do you write a script (monitor_process.sh) that checks whether a given process is running?

  • How do you restart the process automatically if it is not running?

  • How do you log all restart attempts?


Lab 6: Menu-Driven Utility Script

  • How do you create a menu script (menu.sh) with options to:

    • Show current date

    • Show running processes

    • Show disk usage

    • Show memory usage

    • Exit


Lab 7: File Organizer Script

  • How do you write a script (organize_files.sh) that scans a directory?

  • How do you move files into folders based on file extensions (txt, log, jpg)?

  • How do you automatically create folders if they do not exist?


Lab 8: Find & Replace Automation

  • How do you write a script (replace.sh) that accepts:

    • A filename

    • A search term

    • A replacement term

  • How do you replace all occurrences in the file?

  • How do you print the number of lines modified?


Lab 9: Cron Job Setup Script

  • How do you write a script (setup_cron.sh) that creates a cron job running every 5 minutes?

  • How do you configure it to run health.sh and log output to /var/log/health.log?


Lab 10: Automation Script for Server Info

  • How do you write a script (server_info.sh) that displays:

    • OS version

    • Kernel version

    • IP address

    • Uptime

    • Last 5 logins

  • How do you save this information into a timestamped file in /tmp/server-info/?

Last updated