############## SimpleGreaterthanScript #################################
#!/bin/bash
echo "Enter a"
read a
echo "Enter b"
read b
echo "Enter c"
read c
if [[ $a -gt $b && $a -gt $c ]]
then
echo "$a is the biggest of all 3"
elif [[ $b -gt $a && $b -gt $c ]]
then
echo "b is the biggest of all three"
else
echo "c is the biggest of all three"
fi
########## ForLoop #############3333333333333333333333333333333333333333333
#!/bin/bash
#THis will print from 0 to 9
for((i=0 ;i<10 ;i++))
do
echo "$i"
done
#This will print the names of files with extention .sh
for FILE in *.sh
do
echo $FILE
done
################### 3AutoUserAddingScript ###########################
#!bin/bash
add_user()
{
user=$1
password=$2
useradd -m -p $pass $user && echo "User added successfully"
}
##########33############## Zipping and backingup to other folder
#######################
#!/bin/bash
#script to create backup of scripts dir content in backup dir
src_dir=/home/ec2-user/script
dest_dir=/home/ec2-user/backups
curr_timestamp=$(date "+%Y-%m-%d-%H-%M-%S")
bkp_file=$dest_dir/$curr_timestamp.tgz
#Now bkp_file has string with name /home/ec2-user/backup/timestamp.tgz (zip
format)
echo "Taking backup at time $curr_timestamp"
#now tar command will take files from src_dir and make a zip file with timestamp
name in backup folder
tar czf $bkp_file --absolute-names $src_dir
echo "backup complete"
################################### DiskUtilStorageAlarm
###################################################
#!/bin/bash
#limit=90
df -h | awk '{print $5 " " $1}' | while read output;
do
result=$(echo $output | awk '{print $1}' | cut -d'%' -f1)
disk_name=$(echo $output | awk '{print $2}')
# echo "$disk_name"
# echo "$result"
if [ $result -ge 5 ]
then
echo "Alert $disk_name"
else
echo "limit Not crossed"
fi
done
################################# MEMORY COMMANDS
#########################################################
- free >>> to check details of ram used free
- top >>> to check top services consuming cpu and memory utilization.
- df -h >>> shows the whole file system, amount of size filled in eacg file
system and partitions
- awk >>> df -h showed us a huge amt of data, but if we want to sort it and
only see the 1st
and the 5th column of the out put i will use awk.
AWK format eg. df -h | awk '{print $1 " " $5}'