QQ1. Shell Scripting (Linux/UNIX)
- (a)) Write a shell script named backup.sh that performs the following tasks: 1. It should accept a source directory path and a destination directory path as command-line arguments. 2. It should check if the source directory exists. If not, it should print an error message and exit. 3. It should create a compressed backup of the source directory in the destination directory. The backup filename should be in the format backup_YYYY-MM-DD.tar.gz (e.g., backup_2025-10-25.tar.gz). 4. After a successful backup, it should print a message: "Backup of [source_directory] completed successfully at [destination_path/backup_filename]". (250 words)
- (b)) Write another shell script named user_check.sh that takes a username as input. The script should check if the given user is currently logged into the system. If the user is logged in, it should display: "[Username] is currently active on the system." If the user is not logged in, it should display: "[Username] is not logged in." (250 words)
- Shell scripts automate tasks using sequences of Linux commands.
- `tar -czf` creates a gzipped tar archive for directory backups.
- `date +%Y-%m-%d` formats the current date for timestamped filenames.
- `if [ -d "$DIR" ]` checks for the existence of a directory.
Answer: