Script Valley
Linux Basics Complete Course: From Beginner to System Administrator
Module 7: Shell Scripting and Environment/Assessment

Practice & Assessment

Test your understanding of Module 7: Shell Scripting and Environment

Multiple Choice Questions

5
1

What is the purpose of the shebang line (#!/bin/bash) at the top of a shell script?

2

Which command makes a shell script executable?

3

Which journalctl command follows the system journal in real time?

4

In a bash script, what does $1 represent?

5

Which cron expression runs a command every day at 3:00 AM?

Coding Challenges

1
1

Write a System Information Shell Script

Create a bash script called sysinfo.sh that accepts a username as a command-line argument ($1). The script should: print a header with the current date and hostname; check if the argument was provided and exit with an error message if not; display the system uptime; show disk usage for the root partition; show available memory; list the top 5 CPU-consuming processes; check if the provided username exists on the system using grep on /etc/passwd and print an appropriate message. Make the script executable and test it with your own username and a nonexistent username.

Hard
GeeksForGeeks

Mini Project

1

Automated Backup Shell Script

Write a complete bash script called backup.sh that automates directory backups. The script should: accept a source directory and a backup destination directory as arguments; validate that both arguments are provided and that the source directory exists (exit with a clear error message if not); create the backup directory if it does not exist; create a timestamped tar.gz archive of the source directory (filename format: backup-YYYY-MM-DD-HHMMSS.tar.gz); log each backup operation with a timestamp to a log file called backup.log in the backup destination; check if the archive was created successfully and print a success or failure message; remove backup archives older than 7 days from the backup destination using find. Schedule the script to run daily at 2 AM using crontab. Test the script by running it manually with a test directory and verifying the archive and log file were created correctly.

Hard