hexdefender
Email
  • Introduction to Linux
    • Overview
    • Linux Kernel
    • Linux Distros
    • Introduction to Kali Linux
    • Install Kali on VirtualBox
    • Install Kali on AWS
  • Linux Commands
    • Linux File Systems
    • Basic File and Directory commands
    • File Permissions and Ownerships
    • System Commands in Linux
    • Text Processing Commands in Linux
    • Linux Archive Utility
    • Package Management in Kali Linux
    • Networking Commands
    • Disk Utility Tools
    • Linux List of CLI Command lookup
    • Linux CLI Cheatsheet
    • Assignment
  • Networking Essentials
    • Overview
    • Networking Protocols
    • IP Addressing & Subnetting
    • DNS and DNS Security
    • Network Devices and Architecture
    • VPNs and Secure Tunnels
    • Network Address Translation (NAT) & Port Forwarding
    • Wireless Networks & Protocols
    • Cloud Networking & Security
    • Common Network Tools
  • Bash Scripting
    • Fundamentals of Bash
    • Variables, Branching and Loops
    • System Variables in Bash
    • Functions and Error Handling in Bash Scripts
    • File Handling and Text Processing
    • 5 Useful Bash Scripts for Everyday Tasks
    • Useful Assignments
  • Fundamentals of Cybersecurity
    • Introduction to Cybersecurity
    • Importance of Cybersecurity
    • Important Cybersecurity Frameworks
    • Cybersecurity Roles and Career Options
  • Penetration Testing
    • Reconnaissance and Footprinting
    • Exploitation Techniques
      • Introduction
      • Service Enumeration
      • Password Attacks
      • Exploit Discovery
      • The Art of Exploitation
      • The Pentester's guide to Metasploit
    • Post Exploitation - Malware & Escalation
  • Web Application Security
    • Common Web Vulnerabilities
    • OWASP Top 10
    • SQL Injections
    • Cross Site Scripting Attacks
    • Web Application Firewalls
    • Secure Coding Practices
  • Cryptography
    • Basic concepts of cryptography
    • Examples of Asymetric & Hashing functions
    • Public Key Infrastructure
    • Digital Signatures
    • Symmetric and Asymmetric Encryption
  • Social Engineering
    • Introduction to Social Engineering
    • Mitigation Strategies for Social Engineering
  • Digital Forensics
    • Digital Forensics Basics
    • Forensics Tools and Techniques
    • Reverse Engineering Fundamentals
    • Malware Analysis
Powered by GitBook
On this page
  1. Bash Scripting

Useful Assignments


Problem 1: Directory Cleanup Script

Write a Bash script that finds all files in a specified directory that are older than 30 days and deletes them. The script should prompt the user to confirm before proceeding with the deletion.

Requirements:

  • Use command-line argument to specify the directory.

  • Use find command to locate files older than 30 days.

  • Ensure proper validation if the directory doesn’t exist.


Problem 2: User Account Monitoring

Create a Bash script that monitors active user accounts on a Linux system. The script should:

  • List all logged-in users.

  • Write the output to a log file.

  • Include a timestamp indicating when the report was generated.

Requirements:

  • Use who or w to list active users.

  • Append to a log file.


Problem 3: File Backup Automation

Write a script that automatically backs up all files from the ~/Documents directory to a ~/backup/ directory. The script should create the backup directory if it doesn't exist and compress the files into a .tar.gz archive.

Requirements:

  • Validate the existence of the source and destination directories.

  • Include a timestamp in the backup file's name.

  • Use tar to create a compressed archive.


Problem 4: Simple Password Generator

Create a script that generates a random password. The password should include:

  • At least one uppercase letter, one lowercase letter, one digit, and one special character.

  • The script should prompt the user to input the desired password length.

Requirements:

  • Use /dev/urandom or openssl rand.

  • Perform input validation for length (minimum 8 characters).


Problem 5: System Resource Usage Summary

Create a script that gathers and displays a summary of the system's resource usage, including:

  • CPU usage

  • Memory usage

  • Disk space usage

  • Top 5 CPU-consuming processes

Requirements:

  • Use uptime, free -h, df -h, and ps.

  • Display output in a readable format.


Problem 6: Log File Analyzer

Write a script that accepts a log file as input and outputs the top 10 most frequent IP addresses found in the file. The script should handle input validation and check if the file exists.

Requirements:

  • Use grep to search for IP addresses.

  • Use sort and uniq to count occurrences.


Problem 7: Process Killer

Create a script that lists all processes running on the system and prompts the user to select a process to kill based on the process ID (PID). The script should:

  • Validate that the PID entered by the user is valid.

  • Provide confirmation before killing the process.

Requirements:

  • Use ps to list processes.

  • Use kill to terminate the process.


Problem 8: File Permission Checker

Write a script that checks the permissions of all files in a specified directory and lists files that are world-writable (chmod 777). The script should also give the option to change the permissions to chmod 644 for each file found.

Requirements:

  • Use find to locate files with specific permissions.

  • Use chmod to modify file permissions.

  • Implement input validation and confirmation prompts.


Problem 9: Port Scanner

Write a simple port scanner script that scans the first 1024 ports of a given IP address and reports which ports are open.

Requirements:

  • Use nc (netcat) or nmap if available.

  • Validate the IP address input.


Problem 10: Directory Size Monitor

Create a script that monitors the size of a specified directory and notifies the user if it exceeds a certain threshold (e.g., 1GB). The script should run in the background and check the directory size every hour.

Requirements:

  • Use du -sh to check directory size.

  • Use sleep to add a time delay between checks.

  • Send notifications using echo or write to a log file.


Optional Challenge: Interactive Menu

Build a script that offers a menu with options to run any of the above problem scripts (or their solutions). The user should be able to select a script from the menu, run it, and return to the menu afterward.


These assignments cover a range of topics, from file manipulation and process handling to system monitoring and security-related tasks. They help learners develop practical skills while reinforcing Bash scripting concepts. You can evaluate students based on their ability to:

  1. Implement correct logic.

  2. Handle input validation and error handling.

  3. Write clear, maintainable code with comments.

Previous5 Useful Bash Scripts for Everyday TasksNextIntroduction to Cybersecurity

Last updated 8 months ago