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
orw
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
oropenssl 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
, andps
.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
anduniq
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) ornmap
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:
Implement correct logic.
Handle input validation and error handling.
Write clear, maintainable code with comments.
Last updated