Lab 16_ Shell Scripting and Automation
Lab 16_ Shell Scripting and Automation
Objective:
The objective of this lab is to acquire skills in automating tasks through shell scripting.
td
Detailed Steps:
tl
1. Write a Basic Shell Script:
Pv
● Use a text editor such as nano or vim to create a shell script file with a .sh
extension.
ng
nano backup_script.sh
ni
● Write a basic shell script to perform a task such as backing up files. For example:
ar
Le
#!/bin/bash
# Backup script
tar -czvf backup.tar.gz /path/to/files
IE
chmod +x backup_script.sh
AL
crontab -e
● Add an entry to the crontab file to schedule the execution of the shell script at a
specified time or interval.
td
tl
4. Automate System Updates and Monitoring Scripts:
Pv
● Write shell scripts to automate system updates and monitoring tasks.
● For system updates, use package management commands like apt update and
apt upgrade for Debian-based systems or yum update for Red Hat-based
ng
systems.
● For system monitoring, use tools like top, df, free, and custom monitoring
ni
scripts to gather system metrics and log information.
ar
Conclusion:
Le
This lab has provided hands-on experience in shell scripting and automation.
Participants have learned how to write basic shell scripts to automate tasks, assign
execute permissions to scripts, schedule tasks using cron, and automate system
IE
updates and monitoring scripts. These skills are essential for system administrators
and DevOps engineers to streamline repetitive tasks, improve efficiency, and ensure
AF
system reliability.
N
AL