Member-only story
Bash Scripting Applications Explained
Prerequisites:
- Read this blog, which covers basic to advanced bash scripting, and for understanding, please go through the blog linked below:
https://medium.surajshetty.blog/quick-bash-scripting-mastery-for-server-admins-1a8dbd4c7580
Let’s start with the real-life application of bash scripting:
1. Backing up files:
Taking a backup of your files is the most important thing you can do every day.
src_dir=/home/ubuntu/scriptfolder
trgt_dir=/home/ubuntu/backups
curr_timestamp=$(date "+%Y-%m-%d-%H-%M-%S")
backup_file=$trgt_dir/$curr_timestamp.tgz
echo "taking backup on $curr_timestamp"
echo "$backup_file"
tar czf $backup_file --absolute-names $src_dir
echo "Backup complete"2. Add Firewall and Rules:
Adding a firewall and rules is crucial for all servers, and scripting makes it an easy job.
#isntall the firewall
sudo yum install firewalld
sudo systemctl start firewalld
sudo systemctl enable firewalld
sudo firewall-cmd --state
#Setting Firewall Rules
sudo firewall-cmd --permanent --add-port=PORT/tcp
sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="IP_ADDRESS" port protocol="tcp" port="PORT" accept'
sudo firewall-cmd…



