Shell Script - Intermediate
Backup Script
Crete Backup directory:
mkdir /backupsCreate a Backup script
vi backupscript.sh
#!/bin/bash
#Directory of which you need to takebackup src_dir=/home/user1/scripts
#Directory where the backup will be placed.tgt_dir=/backups
#Storing the Date in a variablecurr_timestamp=$(date "+%Y-%m-%d-%H-%M-%S")
#Defining the Backup path and filename (Where the backup will be stored) backup_file=$tgt_dir/$curr_timestamp.tgzecho "Taking Backup on:- $curr_timestamp"#echo "$backup_file"
tar -czf $backup_file --absolute-name $src_direcho "Backup Complete"
Disk Check script
#!/bin/bashdf -H | awk {'print $1 "" "" $5 '} | while read output;do#echo "Disk details: $output"usage=$(echo $output | awk '{print $1}'| cud -d'%' -f1)file_sys=$(echo $output | awk '{print $2}')#echo $usageif [ $usage -ge 90 ]thenecho "CRITICAL for $file_sys"fidone
Or
#!/bin/bashalert=90df -H | awk {'print $1 "" "" $5 '} | while read output;do#echo "Disk details: $output"usage=$(echo $output | awk '{print $1}'| cud -d'%' -f1)file_sys=$(echo $output | awk '{print $2}')#echo $usageif [ $usage -ge $alert ]thenecho "CRITICAL for $file_sys"fidone