├── diskover-2.1.1.zip ├── oroper.sh ├── questions.sh ├── helloworld.sh ├── forloop.sh ├── answers.sh ├── Even_or_Odd_Number.sh ├── eval.sh ├── echo.sh ├── uadd.sh ├── shiftparameters.sh ├── myfirstscript.sh ├── multiplication.sh ├── details.sh ├── while-loop.sh ├── heredoc.sh ├── if-statement.sh ├── for-loop.sh ├── setbashfeature.sh ├── userexists.sh ├── ud.sh ├── if-else-statement.sh ├── or-operator.sh ├── untiloop.sh ├── quotes.sh ├── agtb.sh ├── AutomateLoginSSH.sh ├── add.sh ├── ifs.sh ├── info.sh ├── array.sh ├── countargs.sh ├── spacialvariables.sh ├── getopts.sh ├── functions.sh ├── relationaloper.sh ├── useradd.sh ├── morethanxdays.sh ├── remoteload.sh ├── hi.sh ├── Logical-operators.sh ├── arithmetic.sh ├── memusage.sh ├── function.sh ├── if-elif-if.sh ├── continue.sh ├── variables.sh ├── Arthemetic-Operators.sh ├── diskspace.sh ├── systemload.sh ├── collectroothistory.sh ├── AWS └── s3bucketsize.sh ├── casestatement.sh ├── ExamResults.sh ├── nestedif.sh ├── generate_win_host_config.sh ├── useradd_improved.sh ├── regex.sh ├── CpuMemDisk.sh ├── cpualert.sh ├── convert_and_update_mysql.sh ├── serverinformation.sh ├── webserver_ubuntu.sh └── README.md /diskover-2.1.1.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techarkit/shell-scripting-tutorial/HEAD/diskover-2.1.1.zip -------------------------------------------------------------------------------- /oroper.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Website: https://arkit.co.in 3 | if ! [[ $1 -lt 20 || $2 -ge 30 ]]; then 4 | echo "Statement is True" 5 | else 6 | echo "Statment is False" 7 | fi 8 | -------------------------------------------------------------------------------- /questions.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ## Questions 3 | 4 | echo "Hi" 5 | read $REPLY 6 | 7 | echo "How are you?" 8 | read $REPLY 9 | 10 | echo "Whats your Name?" 11 | read $REPLY 12 | -------------------------------------------------------------------------------- /helloworld.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Purpose: This is the Sample template File 3 | #Version: 1.0 4 | #Created Date: Thu May 3 11:55:43 IST 2018 5 | #Modified Date: 6 | #Author: Ankam Ravi Kumar 7 | # START # 8 | echo "Testing template file" 9 | # END # 10 | -------------------------------------------------------------------------------- /forloop.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Purpose: One more example for for loop 3 | #Version: 4 | #Created Date: Wed May 16 19:31:50 IST 2018 5 | #Modified Date: 6 | #Author: Ankam Ravi Kumar 7 | # START # 8 | for i in 1 2 3 4 5 9 | do 10 | echo $i 11 | done 12 | # END # 13 | -------------------------------------------------------------------------------- /answers.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/expect 2 | 3 | set timeout -1 4 | 5 | spawn ./questions.sh 6 | expect "Hi\r" 7 | send -- "Hi\r" 8 | 9 | expect "How are you?\r" 10 | send -- "I am fine\r" 11 | 12 | expect "Whats your Name?\r" 13 | send -- "My name is Ravi\r" 14 | 15 | expect eof 16 | -------------------------------------------------------------------------------- /Even_or_Odd_Number.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ## To find given number is Even number or Odd Number 3 | 4 | read -p "Enter a number: " number 5 | 6 | if [ $((number % 2)) -eq 0 ]; then 7 | echo "$number is an even number." 8 | else 9 | echo "$number is an odd number." 10 | fi 11 | -------------------------------------------------------------------------------- /eval.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Purpose: eval command Evaluating twice 3 | #Version:1.0 4 | #Created Date: Wed Jun 13 22:09:59 IST 2018 5 | #Modified Date: 6 | #WebSite: https://arkit.co.in 7 | #Author: Ankam Ravi Kumar 8 | # START # 9 | COMMAND="ls -ltr /etc" 10 | echo "$COMMAND" 11 | eval $COMMAND 12 | # END # 13 | -------------------------------------------------------------------------------- /echo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Purpose: eval command Evaluating twice 3 | #Version:1.0 4 | #Created Date: Wed Jun 13 22:09:59 IST 2018 5 | #Modified Date: 6 | #WebSite: https://arkit.co.in 7 | #Author: Ankam Ravi Kumar 8 | # START # 9 | 10 | echo "current location files are `ls`" 11 | echo "current working directory is `pwd`" 12 | 13 | # END # 14 | -------------------------------------------------------------------------------- /uadd.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Purpose: eval command Evaluating twice 3 | #Version:1.0 4 | #Created Date: Wed Jun 13 22:09:59 IST 2018 5 | #Modified Date: 6 | #WebSite: https://arkit.co.in 7 | #Author: Ankam Ravi Kumar 8 | # START # 9 | 10 | echo "ecnter the user name $NM" 11 | read NM 12 | echo "`useradd -d /users/$NM $NM`" 13 | 14 | # END # 15 | -------------------------------------------------------------------------------- /shiftparameters.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Purpose: Shifting positional parameters automatically 3 | #Version:1.0 4 | #Website: https://arkit.co.in 5 | #Created Date: Tue May 22 22:55:50 IST 2018 6 | #Modified Date: 7 | #Author: Ankam Ravi Kumar 8 | # START # 9 | set `date` 10 | echo "Count $#" 11 | echo "$1 $2 $3 $4 $5" 12 | shift 2 13 | echo "$1 $2 $3 $4 $5" 14 | # END # 15 | -------------------------------------------------------------------------------- /myfirstscript.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Purpose: This is my first script in this shell scripting video tutorial 3 | #Date: Wed May 2 17:10:13 IST 2018 4 | #Author: Ankam Ravi Kumar 5 | #Version: 1.0 6 | #Modified Date: 7 | #Modified by: 8 | 9 | # START 10 | echo "Welcome $USERNAME" 11 | echo "Your present working directory is `pwd`" 12 | echo "Today date is `date`" 13 | # END 14 | -------------------------------------------------------------------------------- /multiplication.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Purpose: eval command Evaluating twice 3 | #Version:1.0 4 | #Created Date: Wed Jun 13 22:09:59 IST 2018 5 | #Modified Date: 6 | #WebSite: https://arkit.co.in 7 | #Author: Ankam Ravi Kumar 8 | # START # 9 | 10 | echo "multification of X*Y" 11 | echo "Enter X" 12 | read X 13 | echo "Enter Y" 14 | read Y 15 | echo "X*Y = $X*$Y = $[ X*Y ]" 16 | 17 | # END # -------------------------------------------------------------------------------- /details.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Purpose: eval command Evaluating twice 3 | #Version:1.0 4 | #Created Date: Wed Jun 13 22:09:59 IST 2018 5 | #Modified Date: 6 | #WebSite: https://arkit.co.in 7 | #Author: Ankam Ravi Kumar 8 | # START # 9 | 10 | echo "WEL COME TO $USERNAME" 11 | echo "Your present working directory is `pwd`" 12 | echo "current logged in users are `who`" 13 | echo "Today date is `date`" 14 | 15 | # END # 16 | -------------------------------------------------------------------------------- /while-loop.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # While Loop Example with 2 table, print any given number table. 3 | # See Full Explanation of this above shell script [while loop](https://www.youtube.com/Techarkit?sub_confirmation=1) 4 | 5 | #START 6 | 7 | echo -e "Please provide one value: \c" 8 | read -r c 9 | i=1 10 | while [ $i -le 10 ] 11 | do 12 | b=`expr $c \* $i` 13 | echo "$c * $i = $b" 14 | i=`expr $i + 1` 15 | done 16 | 17 | #END -------------------------------------------------------------------------------- /heredoc.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Purpose: Here Document Example 3 | #Version:1.0 4 | #Created Date: Tue Jun 12 22:50:23 IST 2018 5 | #Modified Date: 6 | #WebSite: https://arkit.co.in 7 | #Author: Ankam Ravi Kumar 8 | # START # 9 | ftp -n <<- EOF 2> /dev/null 10 | open ftp.server.com 11 | user ftp ftp 12 | ascii 13 | cd uploadfolder 14 | mput file1 file1 file2 15 | bye 16 | EOF 17 | 18 | -------------------------------------------------------------------------------- /if-statement.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Purpose: If statement example 3 | #Version:1.0 4 | #Created Date: Sat May 12 23:41:50 IST 2018 5 | #Modified Date: 6 | #Author: Ankam Ravi Kumar 7 | # START # 8 | echo -e "Please provide Value below ten: \c" 9 | read -r value 10 | 11 | if [ $value -le 10 ] 12 | then 13 | echo "You provided value is $value" 14 | touch /tmp/test{1..100}.txt 15 | echo "Script completed successfully" 16 | fi 17 | 18 | # END # 19 | -------------------------------------------------------------------------------- /for-loop.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Purpose: For loop example 3 | #Version:1.0 4 | #website: https://arkit.co.in 5 | #Created Date: Wed May 16 19:26:02 IST 2018 6 | #Modified Date: 7 | #Author: Ankam Ravi Kumar 8 | # START # 9 | for server in `cat /scripts/servers` 10 | do 11 | ping -c 1 $server > /tmp/ping 12 | valid=`echo $?` 13 | if [ $valid -eq 0 ]; then 14 | echo "$server is up" 15 | else 16 | echo "$server is Down" 17 | fi 18 | done 19 | # END # 20 | -------------------------------------------------------------------------------- /setbashfeature.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Purpose: Set assigns its arguments to the positional parameters 3 | #Version:1.0 4 | #website: https://arkit.co.in 5 | #Created Date: Tue May 22 23:10:17 IST 2018 6 | #Modified Date: 7 | #Author: Ankam Ravi Kumar 8 | # START # 9 | set `date` 10 | echo "Today is $1" 11 | echo "Month is $2" 12 | echo "Date is $3" 13 | echo "Time H:M:S $4" 14 | echo "TimeZone is $5" 15 | echo "Year is $6" 16 | set -x 17 | # END # 18 | -------------------------------------------------------------------------------- /userexists.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ##Purpose: Check given user Exits Or Not 3 | ##Date: 27th Oct 2016 4 | ##Author: Ankam Ravi Kumar 5 | ##WebSite: https://arkit.co.in 6 | 7 | ##Start 8 | echo -e "Please Enter User name you want check: \c" 9 | read user 10 | grep $user /etc/passwd > /dev/null 11 | if [ $? -eq 0 ]; then 12 | grep $user /etc/passwd 13 | echo "$user Exists in this Machine" 14 | else 15 | echo "$user does not exists" 16 | fi 17 | 18 | ##END 19 | -------------------------------------------------------------------------------- /ud.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Purpose: eval command Evaluating twice 3 | #Version:1.0 4 | #Created Date: Wed Jun 13 22:09:59 IST 2018 5 | #Modified Date: 6 | #WebSite: https://arkit.co.in 7 | #Author: Ankam Ravi Kumar 8 | # START # 9 | 10 | echo "WEl COME TO $USER" 11 | echo " Your present Wroking Directory is `pwd`" 12 | echo "Present Processes are `ps -a`" 13 | echo "Now Time is `date`" 14 | echo "current logged in Details are `finger $USER`" 15 | 16 | # END # 17 | -------------------------------------------------------------------------------- /if-else-statement.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Purpose: If else statement example 3 | #Version:1.0 4 | #Created Date: Sat May 12 23:49:15 IST 2018 5 | #Modified Date: 6 | #Website: https://arkit.co.in 7 | #Author: Ankam Ravi Kumar 8 | # START # 9 | echo -e "Enter any value: \c" 10 | read -r a 11 | echo -e "Enter any value: \c" 12 | read -r b 13 | 14 | if [ $a -gt $b ]; then 15 | echo "$a is greater than $b" 16 | else 17 | echo "$b is greater than $a" 18 | fi 19 | # END # 20 | -------------------------------------------------------------------------------- /or-operator.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Purpose: OR operator example 3 | #Version:1.0 4 | #Created Date: Sat May 12 21:26:51 IST 2018 5 | #Modified Date: 6 | #Author: Ankam Ravi Kumar 7 | # START # 8 | 9 | echo -e "Enter First Numeric Value: \c" 10 | read -r t 11 | echo -e "Enter Second Numeric Value: \c" 12 | read -r b 13 | 14 | if [ $t -le 20 -o $b -ge 30 ]; then 15 | echo "Statement is True" 16 | else 17 | echo "False Statement, Try Again." 18 | fi 19 | 20 | # END # 21 | -------------------------------------------------------------------------------- /untiloop.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Purpose: Until Loop Example for Host Ping 3 | #Version:1.0 4 | #Created Date: Mon May 28 22:18:52 IST 2018 5 | #Modified Date: 6 | #WebSite: https://arkit.co.in 7 | #Author: Ankam Ravi Kumar 8 | # START # 9 | echo -e "Please Enter the IP Address to Ping: \c" 10 | read -r ip 11 | until ping -c 3 $ip 12 | do 13 | echo "Host $ip is Still Down" 14 | sleep 1 15 | done 16 | 17 | echo "Host $ip is Up Now" 18 | 19 | # END # 20 | -------------------------------------------------------------------------------- /quotes.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Purpose: Verifying Difference between quotation marks 3 | #Version: 1.0 4 | #Created Date: Fri May 4 20:16:55 IST 2018 5 | #Modified Date: 6 | #Author: Ankam Ravi Kumar 7 | # START # 8 | VAR1=123456 9 | TEST=TechArkit 10 | 11 | # Double Quotes 12 | echo "Execute double quotes $VAR1 $TEST" 13 | 14 | # Single Quotes 15 | echo 'Excute Single Quotes $VAR1 $TEST' 16 | 17 | # Reverse Quotes 18 | echo "This Hostname is: `cal`" 19 | 20 | # END # 21 | -------------------------------------------------------------------------------- /agtb.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Purpose: eval command Evaluating twice 3 | #Version:1.0 4 | #Created Date: Wed Jun 13 22:09:59 IST 2018 5 | #Modified Date: 6 | #WebSite: https://arkit.co.in 7 | #Author: Ankam Ravi Kumar 8 | # START # 9 | 10 | echo -e "enter the a value: \c" 11 | read a 12 | echo -e "enter the b value: \c" 13 | read b 14 | if test "$a" -gt "$b" ; then 15 | echo "$a is greater than $b" 16 | else 17 | echo "$b is greater than $a" 18 | fi 19 | 20 | # END # -------------------------------------------------------------------------------- /AutomateLoginSSH.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/expect -f 2 | ## Testing expect command 3 | 4 | ## echo the test 5 | puts "\nGet HostName\n" 6 | 7 | ## execute ssh command to connect to remote host 8 | spawn ssh 192.168.175.130 "hostname" 9 | 10 | ## Look for password string 11 | expect "password:" 12 | 13 | ## Send the password 14 | send "redhat\r" 15 | 16 | puts "\nGet df command output\n" 17 | spawn ssh 192.168.175.130 "df -h" 18 | expect "password:" 19 | send "redhat\r" 20 | interact 21 | -------------------------------------------------------------------------------- /add.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ################################################## 3 | # Purpose: eval command Evaluating twice 4 | # Version:1.0 5 | # Created Date: Wed Jun 13 22:09:59 IST 2018 6 | # Modified Date: 7 | # WebSite: https://arkit.co.in 8 | # Author: Ankam Ravi Kumar 9 | ################################################## 10 | # START # 11 | 12 | echo "addition of X+Y" 13 | echo "Enter X" 14 | read X 15 | echo "Enter Y" 16 | read Y 17 | echo "X+Y = $X+$Y = $[ X+Y ]" 18 | 19 | # END # 20 | -------------------------------------------------------------------------------- /ifs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Purpose: Internal Field Seperator 3 | #Version:1.0 4 | #Created Date: Wed Jun 13 21:58:18 IST 2018 5 | #Modified Date: 6 | #WebSite: https://arkit.co.in 7 | #Author: Ankam Ravi Kumar 8 | # START # 9 | LINE=`cat /etc/passwd |grep $1` 10 | IFS=: 11 | set $LINE 12 | echo "User Name = $1" 13 | echo "Password = $2" 14 | echo "UID = $3" 15 | echo "GID = $4" 16 | echo "Description = $5" 17 | echo "Home Directory = $6 " 18 | echo " Current Shell = $7" 19 | 20 | # END # 21 | -------------------------------------------------------------------------------- /info.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Purpose: eval command Evaluating twice 3 | #Version:1.0 4 | #Created Date: Wed Jun 13 22:09:59 IST 2018 5 | #Modified Date: 6 | #WebSite: https://arkit.co.in 7 | #Author: Ankam Ravi Kumar 8 | # START # 9 | 10 | echo "Hi you there" 11 | echo "what is your name? (Type your name here and press Enter)" 12 | read NM 13 | echo "Hi $NM Good Morning" 14 | echo "your currently logged in as $USERNAME" 15 | echo "your present working directory is `pwd`" 16 | 17 | # END # 18 | -------------------------------------------------------------------------------- /array.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Purpose: Array Example 3 | #Version:1.0 4 | #Created Date: Mon May 28 22:59:22 IST 2018 5 | #Modified Date: 6 | #WebSite: https://arkit.co.in 7 | #Author: Ankam Ravi Kumar 8 | # START # 9 | 10 | fruits=( "Apple" "Orange" "Banana" "Sapota" ) 11 | fruits[3]='Green Apple' 12 | for fruit in ${fruits[@]} 13 | do 14 | echo "Fruit Name is $fruit" 15 | done 16 | 17 | echo "Number of Fruits in Bucket is" ${#fruits[@]} 18 | echo "All Fruits ${fruits[@]}" 19 | 20 | # END # 21 | -------------------------------------------------------------------------------- /countargs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ################################################## 3 | # Purpose: Counting given postional parameters. 4 | # Version:1.0 5 | # Created Date: Mon May 7 21:55:05 IST 2018 6 | # Modified Date: 7 | # Author: Ankam Ravi Kumar 8 | ################################################## 9 | 10 | # START # 11 | echo "Your current given parameters are $#" 12 | if [ $# -lt 1 ];then 13 | echo "Program Usage is './scriptname.sh' options" 14 | else 15 | echo "Program executed successfully" 16 | fi 17 | # END # 18 | -------------------------------------------------------------------------------- /spacialvariables.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Purpose: To learn special variables 3 | #Version:1.0 4 | #Website: https://arkit.co.in 5 | #Created Date: Sun May 6 15:23:12 IST 2018 6 | #Modified Date: 7 | #Author: Ankam Ravi Kumar 8 | # START # 9 | echo "'$*' output is $*" 10 | echo "'$#' output is $#" 11 | echo "'$1 & $2' output $1 and $2" 12 | echo "'$@' output of $@" 13 | echo "'$?' output is $?" 14 | echo "'$$' output is $$" 15 | sleep 400 & 16 | echo "'$!' output is $!" 17 | 18 | echo "'$0' your current program name is $0" 19 | 20 | # END # 21 | -------------------------------------------------------------------------------- /getopts.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Purpose: Getopts Examples working with arguments 3 | #Version:1.0 4 | #Created Date: Wed May 30 22:30:51 IST 2018 5 | #Modified Date: 6 | #WebSite: https://arkit.co.in 7 | #Author: Ankam Ravi Kumar 8 | # START # 9 | 10 | while getopts :a:b: options; do 11 | case $options in 12 | a) ap=$OPTARG;; 13 | b) bo=$OPTARG;; 14 | ?) echo "I Dont know What is $OPTARG is" 15 | esac 16 | done 17 | 18 | echo "Option A = $ap and Option B = $bo" 19 | 20 | # END # 21 | -------------------------------------------------------------------------------- /functions.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Purpose: Example for Functions 3 | #Version:1.0 4 | #Created Date: Sat May 26 00:17:19 IST 2018 5 | #Modified Date: 6 | #WebSite: https://arkit.co.in 7 | #Author: Ankam Ravi Kumar 8 | # START # 9 | function takebackup (){ 10 | if [ -f $1 ]; then 11 | BACKUP="/tmp/$(basename ${1}).$(date +%F).$$" 12 | echo "Backing up $1 to ${BACKUP}" 13 | cp $1 $BACKUP 14 | fi 15 | } 16 | 17 | takebackup /etc/hosts 18 | if [ $? -eq 0 ]; then 19 | echo "Backup Success" 20 | fi 21 | # END # 22 | -------------------------------------------------------------------------------- /relationaloper.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Purpose: Relational Operators examples 3 | #Version:1.0 4 | #Created Date: Thu May 10 22:43:16 IST 2018 5 | #Modified Date: 6 | # Website: https://arkit.co.in 7 | #Author: Ankam Ravi Kumar 8 | # START # 9 | echo -e "Please provide one number: \c" 10 | read -r h 11 | echo -e "Please provide one number: \c" 12 | read -r g 13 | 14 | test $h -lt $g;echo "$?"; 15 | test $h -le $g;echo "$?"; 16 | test $h -gt $g;echo "$?"; 17 | test $h -ge $g;echo "$?"; 18 | test $h -eq $g;echo "$?"; 19 | test $h -ne $g;echo "$?"; 20 | # END # 21 | -------------------------------------------------------------------------------- /useradd.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Script to add a user to Linux system 3 | if [ $(id -u) -eq 0 ]; then 4 | read -p "Enter username : " username 5 | read -s -p "Enter password : " password 6 | egrep "^$username" /etc/passwd >/dev/null 7 | if [ $? -eq 0 ]; then 8 | echo "$username exists!" 9 | exit 1 10 | else 11 | pass=$(perl -e 'print crypt($ARGV[0], "password")' $password) 12 | useradd -m -p $pass $username 13 | [ $? -eq 0 ] && echo "User has been added to system!" || echo "Failed to add a user!" 14 | fi 15 | else 16 | echo "Only root may add a user to the system" 17 | exit 2 18 | fi 19 | -------------------------------------------------------------------------------- /morethanxdays.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ## Delete the Directories older than 2 days based on directory name validation 3 | ## Refer YouTube Link for Explanation https://youtu.be/1Sh6PWcgXAA 4 | ls -ltr /fullbackup/archive/ | awk '{print $9}' > /scripts/dirs 5 | for i in `cat /scripts/dirs`; do 6 | STARTTIME=$(date +%s -d"$i 00:00:00") 7 | ENDTIME=$(date +%s) 8 | echo $((ENDTIME-STARTTIME)) | awk '{print int($1/60)}' > /scripts/value 9 | COUNT=`cat /scripts/value` 10 | if [ $COUNT -gt 2880 ]; then 11 | echo "Directories are older than 2days $i" >> /scripts/joblog 12 | rm -rf /fullbackup/archive/$i 13 | fi 14 | done 15 | -------------------------------------------------------------------------------- /remoteload.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ################################################## 3 | # # 4 | # Author: Ankam Ravi Kumar # 5 | # Website: server-computer.com # 6 | # Date: 23-02-2019 16:59:56 # 7 | # Purpose: Capture and Store System Load Average # 8 | # CPU Usage and Memory Usage # 9 | ################################################## 10 | # Log File Path 11 | LOGFILE=/var/log/systemload.log 12 | 13 | echo "" > /tmp/remotelog 14 | 15 | for i in `cat /opt/hostnames`; 16 | do 17 | cat /root/systemload.sh | ssh $i >> /tmp/remotelog 18 | done 19 | 20 | cat /tmp/remotelog |grep -vE "^Last|^There" >> $LOGFILE 21 | -------------------------------------------------------------------------------- /hi.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Purpose: eval command Evaluating twice 3 | #Version:1.0 4 | #Created Date: Wed Jun 13 22:09:59 IST 2018 5 | #Modified Date: 6 | #WebSite: https://arkit.co.in 7 | #Author: Ankam Ravi Kumar 8 | # START # 9 | 10 | tmp=`date | cut -c12-13` 11 | if [ $tmp -lt 11 ] ; then 12 | echo "Good Mornind have a nice day $USERNAME" 13 | elif [ $tmp -gt 11 -a $tmp -lt 16 ] ; then 14 | echo "Good Ofter noon $USERNAME" 15 | elif [ $tmp -gt 15 -a $tmp -lt 19 ] ; then 16 | echo "Good Evening $USERNAME" 17 | else 18 | echo "Good Night Sweet dreams $USERNAME" 19 | fi 20 | echo "Now the time is `date |cut -c12-19`" 21 | 22 | # END # 23 | -------------------------------------------------------------------------------- /Logical-operators.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Purpose: Logical Operators/Boolean Operators. Student Marks Validation. 3 | #Version:1.0 4 | #Created Date: Sat May 12 21:21:03 IST 2018 5 | #Modified Date: 6 | #Author: Ankam Ravi Kumar 7 | # START # 8 | echo -e "Enter Your Maths Subject Marks: \c" 9 | read -r m 10 | echo -e "Enter Your Physics Subject Marks: \c" 11 | read -r p 12 | echo -e "Enter Your Chemistry Subject Marks: \c" 13 | read -r c 14 | 15 | if test $m -ge 35 -a $p -ge 35 -a $c -ge 35 16 | then 17 | echo "Congratulations, You have passed in all subjects" 18 | else 19 | echo "Sorry You not upto mark in one of the subject" 20 | fi 21 | # END # 22 | -------------------------------------------------------------------------------- /arithmetic.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Purpose:Arthmetic operators using expr command 3 | #Version:1.0 4 | #Created Date: Wed May 9 21:47:04 IST 2018 5 | #Modified Date: 6 | #website: https://arkit.co.in 7 | #Author: Ankam Ravi Kumar 8 | # START # 9 | echo -e "Enter value: \c" 10 | read -r a 11 | echo -e "Enter value: \c" 12 | read -r b 13 | 14 | echo "addition values `expr $a + $b`" 15 | echo "minus values `expr $a - $b`" 16 | echo "multiplied by values `expr $a \* $b`" 17 | echo "devided by values `expr $a / $b`" 18 | echo "remainder values `expr $a % $b`" 19 | echo "addition values `expr $a + $b`" 20 | 21 | echo "Completed Sucessfully" 22 | # END # 23 | -------------------------------------------------------------------------------- /memusage.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ## Monitoring Memory usage of the server 3 | # Version:1.0 4 | # Created Date: 2022-Jan-07 5 | # WebSite: https://arkit.co.in 6 | # Author: Ankam Ravi Kumar 7 | 8 | HOSTNAME=$(hostname) 9 | DATED=$(date "+%Y-%m-%d %H:%M:%S") 10 | THRESHOLD=80 11 | TOADDRESS=aravikumar48@gmail.com 12 | 13 | MEMUSAGE=$(free | grep Mem | awk '{print $3/$2 * 100.0}' |awk -F. '{print $1}') 14 | if [ $MEMUSAGE -ge $THRESHOLD ]; then 15 | echo "$HOSTNAME, $DATED, %MEMUSAGE" >> /var/log/memusage_history 16 | echo "$HOSTNAME, $DATED, %MEMUSAGE" > /tmp/memusage 17 | mail -s "$HOSTNAME $DATED Mem Usage: $MEMUSAGE" $TOADDRESS <<< /tmp/memusage 18 | fi 19 | -------------------------------------------------------------------------------- /function.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Purpose: Function example. Taking Backup of Particular File 3 | #Version:1.0 4 | #Created Date: 2024 Sep 21 5 | #Modified Date: 6 | #WebSite: https://arkit.co.in 7 | #Author: Ankam Ravi Kumar 8 | 9 | # START # 10 | function takebackup (){ 11 | if [ -f $1 ]; then 12 | BACKUP="/home/aravi/$(basename ${1}).$(date +%F).$$" 13 | echo "Backing up $1 to ${BACKUP}" 14 | cp $1 $BACKUP 15 | fi 16 | } 17 | 18 | takebackup /etc/hosts 19 | if [ $? -eq 0 ]; then 20 | echo "BAckup Success" 21 | fi 22 | function testing (){ 23 | echo "Just TEsting Function" 24 | } 25 | 26 | testing 27 | # END # 28 | -------------------------------------------------------------------------------- /if-elif-if.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Purpose: Find biggest Number among 4 digits 3 | #Version:1.0 4 | #Created Date: Wed May 16 18:45:58 IST 2018 5 | #Modified Date: 6 | #Author: Ankam Ravi Kumar 7 | # START # 8 | 9 | echo -e "Please Enter a Value: \c" 10 | read -r a 11 | echo -e "Please Enter b Value: \c" 12 | read -r b 13 | echo -e "Please Enter c Value: \c" 14 | read -r c 15 | echo -e "Please Enter d Value: \c" 16 | read -r d 17 | 18 | if [ $a -gt $b -a $a -gt $c -a $a -gt $d ]; then 19 | echo "$a a is big" 20 | elif [ $b -gt $c -a $b -gt $d ]; then 21 | echo "$b b is big" 22 | elif [ $c -gt $d ]; then 23 | echo "$c c is big" 24 | else 25 | echo "$d d is big" 26 | fi 27 | 28 | # END # 29 | -------------------------------------------------------------------------------- /continue.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Purpose: While loop Continue Statement 3 | #Version:1.0 4 | #Website: https://arkit.co.in 5 | #Created Date: Tue May 22 22:03:02 IST 2018 6 | #Modified Date: 7 | #Author: Ankam Ravi Kumar 8 | # START # 9 | opt=y 10 | while [ $opt = y -o $opt = Y ] 11 | do 12 | echo -e "Please enter the number: \c" 13 | read -r num 14 | if [ $num -le 50 ]; then 15 | sq=`expr $num \* $num` 16 | echo "Square of provided number $num: $sq" 17 | else 18 | echo "Number not in the given Range" 19 | fi 20 | 21 | echo -e "Do you want to continue [y/n]: \c" 22 | read -r wish 23 | if [ $wish = y -o $wish = Y ]; then 24 | continue 25 | else 26 | echo "Thank You for Exiting.." 27 | exit 28 | fi 29 | done 30 | 31 | # END # 32 | -------------------------------------------------------------------------------- /variables.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Purpose: What is variable.? How is help us in writing shell scripts 3 | #Version:1.0 4 | #Created Date: Sat May 5 20:25:21 IST 2018 5 | #Modified Date: 6 | #website: https://arkit.co.in 7 | #Author: Ankam Ravi Kumar 8 | # START # 9 | 10 | A=10 11 | Ba=23 12 | BA=45 13 | HOSTNAME=$(hostname) 14 | DATE=`date` 15 | 1value=333 16 | False@Var=False 17 | Hyphen_a=WrongValue 18 | 19 | echo "Variable A Value: $A" 20 | echo "Variable Ba Vaule: $Ba" 21 | echo "Variable BA Vaule: $BA" 22 | echo "Variable HOST value: $HOSTNAME" 23 | echo "Variable DATE value: $DATE" 24 | echo "Wrong Variable 1value $1value" 25 | echo 'False @ Variable' $False@Var 26 | echo "hyphen-a Variable Value: $Hyphen_a" 27 | 28 | # END # 29 | -------------------------------------------------------------------------------- /Arthemetic-Operators.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Purpose: Arthemetic Operators 3 | #Version:1.0 4 | #Created Date: Wed May 9 21:41:53 IST 2018 5 | #Modified Date: 6 | #Author: Ankam Ravi Kumar 7 | # START # 8 | 9 | echo -e "Please enter some value: \c" 10 | read -r a 11 | echo -e "Please enter another value: \c" 12 | read -r b 13 | 14 | echo "a+b value is $(($a+$b))" #it will add both the values 15 | echo "a-b value is $(($a-$b))" #it will subtract b form a 16 | echo "axb value is $(($a*$b))" #it will multiply both a and b 17 | echo "a/b value is $(($a/$b))" #it will divide b from a 18 | echo "a%b value is $(($a%$b))" #it will give the remainder when a is divided by b 19 | 20 | echo "Completed successfully" 21 | 22 | # END # 23 | -------------------------------------------------------------------------------- /diskspace.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Purpose: Monitoring Disk Space Utilization and Send Email Alert 3 | #Version:1.0 4 | #Created Date: Wed Jun 6 22:38:01 IST 2018 5 | #Modified Date: 6 | #WebSite: https://arkit.co.in 7 | #Author: Ankam Ravi Kumar 8 | # START # 9 | THRESHOULD=40 10 | mailto="root" 11 | HOSTNAME=$(hostname) 12 | 13 | for path in `/bin/df -h | grep -vE 'Filesystem|tmpfs' | awk '{print $5}' |sed 's/%//g'` 14 | do 15 | if [ $path -ge $THRESHOULD ]; then 16 | df -h | grep $path% >> /tmp/temp 17 | fi 18 | done 19 | 20 | VALUE=`cat /tmp/temp | wc -l` 21 | if [ $VALUE -ge 1 ]; then 22 | mail -s "$HOSTNAME Disk Usage is Critical" $mailto < /tmp/temp 23 | fi 24 | 25 | #rm -rf /tmp/temp 26 | 27 | 28 | # END # 29 | -------------------------------------------------------------------------------- /systemload.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ################################################## 3 | # # 4 | # Author: Ankam Ravi Kumar # 5 | # Website: server-computer.com # 6 | # Date: 23-02-2019 16:59:56 # 7 | # Purpose: Capture and Store System Load Average # 8 | # CPU Usage and Memory Usage # 9 | ################################################## 10 | # Log File Path 11 | LOGFILE=/var/log/systemload.log 12 | 13 | HOSTNAME=$(hostname) 14 | DATE=$(date "+%d-%m-%Y %H:%M:%S") 15 | SYSTEMLOAD=$(uptime | awk '{ print $8,$9,$10,$11,$12}') 16 | CPULOAD=$(top -b -n 2 -d1 | grep "Cpu(s)" | tail -n1 |awk '{print $2}') 17 | MEMORYUSAGE=$(free -m |grep Mem: |tail -n1 |awk '{print $2,$3}') 18 | 19 | echo "$DATE $HOSTNAME LoadAverage: $SYSTEMLOAD CPU: $CPULOAD Memory: $MEMORYUSAGE" >> $LOGFILE 20 | -------------------------------------------------------------------------------- /collectroothistory.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ## Collect Root Commands History 3 | 4 | # Mailing List 5 | MAILLIST="YOUREMAIL@DOMAIN" 6 | 7 | # Log path 8 | AUDLOG="/rootcommands" 9 | 10 | cp /root/.bash_history /tmp/history 11 | sed -i 's/#//g' /tmp/history 12 | for i in `cat /tmp/history |grep ^[0-9]` 13 | do 14 | CONVT=`date -d @$i` 15 | sed -i "s/$i/$CONVT/g" /tmp/history 16 | done 17 | 18 | sed -i 'N;s/\n/ /' /tmp/history 19 | sleep 10 20 | 21 | /bin/touch ${AUDLOG}$HOSTNAME-root-hist.log.`date +%h%d%y` 22 | /bin/grep "$DATE" /tmp/history > ${AUDLOG}$HOSTNAME-root-hist.log.`date +%h%d%y` 23 | /bin/chmod 0440 ${AUDLOG}$HOSTNAME-root-hist.log.`date +%h%d%y` 24 | 25 | # Mail notification 26 | /bin/cat ${AUDLOG}$HOSTNAME-root-hist.log.`date +%h%d%y` |mail -s "HOST: $HOSTNAME - `whoami` Daily root Commands Log" ${MAILLIST} 27 | -------------------------------------------------------------------------------- /AWS/s3bucketsize.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Purpose: To Know S3 Bucket Size Shell Script 3 | #Version:1.0 4 | #Created Date: 09-Jan-2019 5 | #Modified Date: 6 | #WebSite: https://www.server-computer.com 7 | #Author: Ankam Ravi Kumar 8 | # START # 9 | echo -e "Please Enter your Bucket Name: \c" 10 | read -r BUCKETNAME 11 | aws s3api list-objects --bucket $BUCKETNAME --output json --query "[sum(Contents[].Size)]" > $PWD/s3bucket 12 | sed -i 's/\[//' $PWD/s3bucket 13 | sed -i 's/]//' $PWD/s3bucket 14 | sed -i 's/ //' $PWD/s3bucket 15 | cat $PWD/s3bucket |head -2 |tail -1 |awk '{print int($1/1024)" KB"}' 16 | cat $PWD/s3bucket |head -2 |tail -1 |awk '{print int($1/1024/1024)" MB"}' 17 | cat $PWD/s3bucket |head -2 |tail -1 |awk '{print int($1/1024/1024/1024)" GB"}' 18 | cat $PWD/s3bucket |head -2 |tail -1 |awk '{print int($1/1024/1024/1024/1024)" TB"} 19 | -------------------------------------------------------------------------------- /casestatement.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Purpose: Example for Case Statement 3 | #Version:1.0 4 | #WebSite: https://arkit.co.in 5 | #Created Date: Mon May 21 20:37:59 IST 2018 6 | #Modified Date: 7 | #Author: Ankam Ravi Kumar 8 | # START # 9 | echo -e "Enter a number: \c" 10 | read -r a 11 | echo -e "Enter b number: \c" 12 | read -r b 13 | 14 | echo "1. Sum of values" 15 | echo "2. Substraction" 16 | echo "3. Multiplication" 17 | echo "4. Division" 18 | echo "5. Modulo division" 19 | echo -e "Enter Your Choice from above menu: \c" 20 | read -r ch 21 | case $ch in 22 | 1) echo "Sum of $a + $b = "`expr $a + $b`;; 23 | 2) echo "Subsctraction = "`expr $a - $b`;; 24 | 3) echo "Multiplication = "`expr $a \* $b`;; 25 | 4) echo "Division = "`expr $a / $b`;; 26 | 5) echo "Modulo Division = "`expr $a % $b`;; 27 | *) echo "Invalid Option provided" 28 | esac 29 | # END # 30 | -------------------------------------------------------------------------------- /ExamResults.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Purpose: Validate and report Student subject marks 3 | #Version:1.0 4 | #Created Date: 2024 sep 5 | #Modified Date: 6 | #Author: Ankam Ravi Kumar 7 | # START # 8 | 9 | echo -e "Please Enter Maths Marks: \c" 10 | read -r m 11 | echo -e "Please Enter Physics Marks: \c" 12 | read -r p 13 | echo -e "Please Enter Chemistry Marks: \c" 14 | read -r c 15 | 16 | if [ $m -ge 35 -a $p -ge 35 -a $c -ge 35 ]; then 17 | total=`expr $m + $p + $c` 18 | avg=`expr $total / 3` 19 | echo "Total Marks = $total" 20 | echo "Average Marks = $avg" 21 | if [ $avg -ge 75 ]; then 22 | echo "Congrats you got Distinction" 23 | elif [ $avg -ge 60 -a $avg -lt 75 ]; then 24 | echo "Congrats you got First Class" 25 | elif [ $avg -ge 50 -a $avg -lt 60 ]; then 26 | echo "You got second class" 27 | elif [ $avg -ge 35 -a $avg -lt 50 ]; then 28 | echo "You Got Third Class" 29 | fi 30 | else 31 | echo "Sorry You Failed" 32 | fi 33 | 34 | # END # 35 | -------------------------------------------------------------------------------- /nestedif.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Purpose: Validate and report Student subject marks 3 | #Version:1.0 4 | #Created Date: Wed May 16 19:00:52 IST 2018 5 | #Modified Date: 6 | #Author: Ankam Ravi Kumar 7 | # START # 8 | 9 | echo -e "Please Enter Maths Marks: \c" 10 | read -r m 11 | echo -e "Please Enter Physics Marks: \c" 12 | read -r p 13 | echo -e "Please Enter Chemistry Marks: \c" 14 | read -r c 15 | 16 | if [ $m -ge 35 -a $p -ge 35 -a $c -ge 35 ]; then 17 | total=`expr $m + $p + $c` 18 | avg=`expr $total / 3` 19 | echo "Total Marks = $total" 20 | echo "Average Marks = $avg" 21 | if [ $avg -ge 75 ]; then 22 | echo "Congrats you got Distinction" 23 | elif [ $avg -ge 60 -a $avg -lt 75 ]; then 24 | echo "Congrats you got First Class" 25 | elif [ $avg -ge 50 -a $avg -lt 60 ]; then 26 | echo "You got second class" 27 | elif [ $avg -ge 35 -a $avg -lt 50 ]; then 28 | echo "You Got Third Class" 29 | fi 30 | else 31 | echo "Sorry You Failed" 32 | fi 33 | 34 | # END # 35 | -------------------------------------------------------------------------------- /generate_win_host_config.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ## Purpose: To Generate Nagios Configuration files within minute of time. 3 | ## Author: Ankam Ravi Kumar 4 | 5 | mkdir -p /scripts/WinServers 6 | cat /scripts/serverlist.txt | while read LINE 7 | do 8 | HostIP=`echo $LINE | cut -d, -f1` 9 | HostName=`echo $LINE | cut -d, -f2` 10 | 11 | NSCLIENTSTATE=$(/usr/local/nagios/libexec/check_nt -H $HostIP -p 12489 -v CLIENTVERSION -s Password | echo $?) 12 | if [ $NSCLIENTSTATE -eq 0 ]; then 13 | sed -e "s/XXXX/$HostName/g; s/ZZZZ/$HostIP/g" /scripts/Template-Windows.cfg > /scripts/WinServers/$HostName.cfg 14 | 15 | for i in D E F G H I J K L M N O P Q R S T U V W X Y Z; 16 | do 17 | /usr/local/nagios/libexec/check_nt -H $HostIP -p 12489 -v USEDDISKSPACE -s Password -l $i -w 90 -c 95 18 | COMMANDSTATUS=$(echo $?) 19 | if [ $COMMANDSTATUS -eq 0 ] || [ $COMMANDSTATUS -eq 2 ];then 20 | sed -e "s/XXXX/$HostName/g; s/ZZZZ/$i/g" /scripts/Drives.cfg >> /scripts/WinServers/$HostName.cfg 21 | fi 22 | done 23 | fi 24 | done 25 | -------------------------------------------------------------------------------- /useradd_improved.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ## Author: Ankam Ravi Kumar 3 | ## Date: 21st Sep 2024 4 | ## Purpose: To Create a users in Linux 5 | 6 | check_command_success() { 7 | if [ $? -ne 0 ]; then 8 | echo "Error: $1" 9 | exit 1 10 | fi 11 | } 12 | 13 | if [ $(id -u) -ne 0 ]; then 14 | echo "Error: Only root may add a user to the system." 15 | exit 2 16 | fi 17 | 18 | # Prompt for the username and password 19 | read -p "Enter username: " username 20 | read -s -p "Enter password: " password 21 | echo 22 | 23 | if id "$username" &>/dev/null; then 24 | echo "Error: User '$username' already exists!" 25 | exit 1 26 | fi 27 | 28 | encrypted_password=$(perl -e 'print crypt($ARGV[0], "password")' "$password") 29 | check_command_success "Failed to encrypt the password." 30 | 31 | useradd -m -p "$encrypted_password" "$username" 32 | check_command_success "Failed to add the user." 33 | 34 | passwd -e "$username" 35 | check_command_success "Failed to set password expiry." 36 | 37 | echo "Success: User '$username' has been added to the system!" 38 | -------------------------------------------------------------------------------- /regex.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Purpose: regex examples 3 | #Version: 1.0 4 | #Create Date: Sun Nov 27 00:27:33 EST 2022 5 | #Modified Date: 6 | 7 | # START # 8 | 9 | numString1="1234" 10 | numString2="16789" 11 | numString3="1579" 12 | 13 | 14 | echo "Example 1" 15 | if [[ $numString1 =~ ^1 ]]; then 16 | echo "String \"$numString1\" starts with a \"1\", and matches regex: ^1" 17 | fi 18 | 19 | echo "Example 2" 20 | if [[ $numString2 =~ ^1 ]]; then 21 | echo "String \"$numString2\" starts with a \"1\", and matches regex: ^1" 22 | fi 23 | 24 | echo "Example 3" 25 | if [[ $numString3 =~ ^1.7 ]]; then 26 | echo "String \"$numString2\" starts with a \"1\", followed by any character, and followed by a 7. " 27 | echo "This string matches the regex: ^1.7" 28 | fi 29 | 30 | echo "Example 4" 31 | if [[ ! $numString1 =~ ^1.7 ]]; then 32 | echo "String \"$numString1\" does not start with a \"1\", followed by any character, and followed by a 7. " 33 | echo "This string does not match the regex: ^1.7" 34 | fi 35 | 36 | echo "Example 5" 37 | if [[ $numString2 =~ 9$ ]]; then 38 | echo "String \"$numString2\" ends with a \"9\", and matches the regex: 9$" 39 | fi 40 | 41 | -------------------------------------------------------------------------------- /CpuMemDisk.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ## Collect Multiple Servers CPU, MEM and DISK Utilization and store in single file 3 | # Purpose: To Collect Multiple Servers CPU, MEM, DISK usage in single report 4 | # Version:1.0 5 | # Created Date: 2019-05-02 6 | # Modified Date: 7 | # WebSite: https://arkit.co.in 8 | # Author: Ankam Ravi Kumar 9 | 10 | HOSTNAME=$(hostname) 11 | DATET=$(date "+%Y-%m-%d %H:%M:%S") 12 | CPUUSAGE=$(top -b -n 2 -d1 | grep "Cpu(s)" | tail -n1 | awk '{print $2}' |awk -F. '{print $1}') 13 | MEMUSAGE=$(free | grep Mem | awk '{print $3/$2 * 100.0}') 14 | DISKUSAGE=$(df -h / | awk '{print $5}' |tail -n 1 |sed 's/%//g') 15 | 16 | echo 'HostName, Date&Time, CPU(%), MEM(%), DISK(%)' >> /opt/usagereport 17 | echo "$HOSTNAME, $DATET, $CPUUSAGE, $MEMUSAGE, $DISKUSAGE" >> /opt/usagereport 18 | 19 | for i in `cat /scripts/hostlist` 20 | do 21 | RHOST=$(ssh $i hostname) 22 | RDATET=$(ssh $i 'date "+%Y-%m-%d %H:%M:%S"') 23 | RCPUUSAGE=$(ssh $i top -b -n 2 -d1 | grep "Cpu(s)" | tail -n1 | awk '{print $2}' |awk -F. '{print $1}') 24 | RMEMUSAGE=$(ssh $i free | grep Mem | awk '{print $3/$2 * 100.0}') 25 | RDISKUSAGE=$(ssh $i df -P / |column -t | awk '{print $5}' |tail -n 1 |sed 's/%//g') 26 | 27 | echo "$RHOST, $RDATET, $RCPUUSAGE, $RMEMUSAGE, $RDISKUSAGE" >> /opt/usagereport 28 | done 29 | -------------------------------------------------------------------------------- /cpualert.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Purpose: Real time CPU utilization Monitoring 3 | #Version:1.0 4 | #Created Date: Tue Jun 5 21:33:38 IST 2018 5 | #Modified Date: 6 | #WebSite: https://arkit.co.in 7 | #Author: Ankam Ravi Kumar 8 | # START # 9 | PATHS="/" 10 | HOSTNAME=$(hostname) 11 | CRITICAL=98 12 | WARNING=90 13 | CRITICALMail="YOUREMAILaddresS@Domain.com" 14 | MAILWAR="YOUREMAIL@Domain.in" 15 | mkdir -p /var/log/cputilhist 16 | LOGFILE=/var/log/cputilhist/cpusage-`date +%h%d%y`.log 17 | 18 | touch $LOGFILE 19 | 20 | for path in $PATHS 21 | do 22 | CPULOAD=`top -b -n 2 -d1 | grep "Cpu(s)" | tail -n1 | awk '{print $2}' |awk -F. '{print $1}'` 23 | if [ -n $WARNING -a -n $CRITICAL ]; then 24 | if [ "$CPULOAD" -ge "$WARNING" -a "$CPULOAD" -lt "$CRITICAL" ]; then 25 | echo "`date "+%F %H:%M:%S"` WARNING - $CPULOAD on Host $HOSTNAME" >> $LOGFILE 26 | echo "Warning Cpuload $CPULOAD Host is $HOSTNAME" | mail -s "CPULOAD is Warning" $MAILWAR 27 | exit 1 28 | elif [ "$CPULOAD" -ge "$CRITICAL" ]; then 29 | echo "`date "+%F %H:%M:%S"` CRITICAL - $CPULOAD on Host $HOSTNAME" >> $LOGFILE 30 | echo "CRITICAL Cpuload $CPULOAD Host is $HOSTNAME" | mail -s "CPULOAD is CRITICAL" $CRITICALMail 31 | exit 2 32 | else 33 | echo "`date "+%F %H:%M:%S"` OK - $CPULOAD on $HOSTNAME" >> $LOGFILE 34 | exit 0 35 | fi 36 | fi 37 | done 38 | 39 | # END # 40 | -------------------------------------------------------------------------------- /convert_and_update_mysql.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | n=1 4 | until [ $n -gt 11196 ] 5 | do 6 | EXIRECORDS=$(mysql -u root -pPASSWORD -h 192.168.2.100 -e "SELECT sn,tarsize from DATABASE.Table1 where sn='"$n"'" |tail -n1 |grep $n) 7 | 8 | RECORDNUMBER=$(echo $EXIRECORDS |awk '{print $1}') 9 | FOLDERSIZE=$(echo $EXIRECORDS |awk '{print $2}') 10 | 11 | KB=$(echo $EXIRECORDS |awk '{print $2}' |grep K |wc -l) 12 | if [ $KB -ge 1 ]; then 13 | K=$(echo $EXIRECORDS |awk '{print $2}' |sed 's/K//g') 14 | BYTES=$($K * 1024 |bc |awk -F. '{print $1}') 15 | mysql -u root -pPASSWORD -h 192.168.2.100 -e "UPDATE DATABASE.Table1 SET tarsize='"$BYTES"' where sn='"$RECORDNUMBER"'" 16 | fi 17 | 18 | MB=$(echo $EXIRECORDS |awk '{print $2}' |grep M |wc -l) 19 | if [ $MB -ge 1 ]; then 20 | M=$(echo $EXIRECORDS |awk '{print $2}' |sed 's/M//g') 21 | BYTES=$(echo $M*1024*1024 |bc |awk -F. '{print $1}') 22 | mysql -u root -pPASSWORD -h 192.168.2.100 -e "UPDATE DATABASE.Table1 SET tarsize='"$BYTES"' where sn='"$RECORDNUMBER"'" 23 | fi 24 | 25 | GB=$(echo $EXIRECORDS |awk '{print $2}' |grep G |wc -l) 26 | if [ $GB -ge 1 ]; then 27 | G=$(echo $EXIRECORDS |awk '{print $2}' |sed 's/G//g') 28 | BYTES=$(echo $G*1024*1024*1024 |bc |awk -F. '{print $1}') 29 | mysql -u root -pPASSWORD -h 192.168.2.100 -e "UPDATE DATABASE.Table1 SET tarsize='"$BYTES"' where sn='"$RECORDNUMBER"'" 30 | fi 31 | 32 | TB=$(echo $EXIRECORDS |awk '{print $2}' |grep T |wc -l) 33 | if [ $TB -ge 1 ]; then 34 | T=$(echo $EXIRECORDS |awk '{print $2}' |sed 's/T//g') 35 | BYTES=$(echo $T*1024*1024*1024*1024 |bc |awk -F. '{print $1}') 36 | mysql -u root -pPASSWORD -h 192.168.2.100 -e "UPDATE DATABASE.Table1 SET tarsize='"$BYTES"' where sn='"$RECORDNUMBER"'" 37 | fi 38 | 39 | 40 | n=`expr "$n" + 1` 41 | 42 | done 43 | -------------------------------------------------------------------------------- /serverinformation.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | mkdir -p /Inventory 4 | sudo chmod -R 777 /Inventory/ 5 | mkdir -p /tmp/asset 6 | touch /tmp/asset/hostname.txt 7 | if [ -f /tmp/asset/hostname.txt ];then 8 | echo "File /tmp/asset/hostname.txt Exists" 9 | else 10 | mkdir /tmp/asset 11 | touch /tmp/asset/hostname.txt 12 | fi 13 | touch /tmp/temptext 14 | TEMP=/tmp/temptext 15 | LOG=`ls /tmp/asset/hostname.txt` 16 | echo "## Host Information" > $LOG 17 | echo "Host Name : `hostname` " >> $LOG 18 | echo "`sudo /sbin/ifconfig -a |grep "inet" | awk 'BEGIN { FS = ":" } ; { print $2 }'`" >> $TEMP 19 | echo "IP Address : `egrep '^10' $TEMP |awk '{ print $1}'`" >> $LOG 20 | echo "IP Address: `hostname -I`" >> $LOG 21 | echo "ip a |grep inet |grep -v "::" |awk '{print $2}'" >> $LOG 22 | echo "iDrac Details: `racadm getniccfg |grep "IP Address" |grep -v "::"`" >> $LOG 23 | echo "Server Type: `servertype=$(lscpu | grep Hypervisor | wc -l); if [ $servertype -gt 0 ]; then echo "VitualMachine"; else echo "Physical"; fi`" >> $LOG 24 | echo -en '\n' >> $LOG 25 | 26 | ## Collecting Hardware Details ## 27 | echo " " >> $LOG 28 | echo "## Hardware Information" >> $LOG 29 | echo " " >> $LOG 30 | echo "Serial Number : `sudo lshal |grep system.hardware.serial`" >> $LOG 31 | echo "Serial Number : `sudo /usr/sbin/dmidecode -s system-serial-number`" >> $LOG 32 | echo "Serial Number : `sudo cat /sys/class/dmi/id/product_serial`" >> $LOG 33 | echo "Model Number : `sudo lshal |grep system.hardware.product`" >> $LOG 34 | echo "Model Number : `sudo /usr/sbin/dmidecode |grep "SKU Number"`" >> $LOG 35 | echo "Model Number : `sudo cat /sys/class/dmi/id/product_name`" >> $LOG 36 | echo "Hardware Vendor : `sudo lshal |grep system.hardware.vendor`" >> $LOG 37 | echo "Hardware Vendor : `sudo cat /sys/class/dmi/id/chassis_vendor`" >> $LOG 38 | echo "Hardware Info : `sudo dmesg |grep DMI`" >> $LOG 39 | 40 | ## Redhat Version ## 41 | echo " " >> $LOG 42 | echo "## OS Version" >> $LOG 43 | head -n1 /etc/issue >> $LOG 44 | cat /etc/redhat-release >> $LOG 45 | echo "Kernel Version: `uname -r`">> $LOG 46 | echo "OS Version: `hostnamectl | egrep "Operating System" | cut -d ' ' -f5-`" >> $LOG 47 | 48 | ## CPU Info ## 49 | echo " " >> $LOG 50 | echo " " >> $LOG 51 | echo "## CPU Information" >> $LOG 52 | grep "model name" /proc/cpuinfo |uniq >> $LOG 53 | COUNTT=$(cat /proc/cpuinfo |grep "model name" | wc -l) 54 | echo "$COUNTT Cores" >> $LOG 55 | 56 | ## RAM/MEMORY Info ## 57 | echo " " >> $LOG 58 | echo " " >> $LOG 59 | echo "## Memory Information" >> $LOG 60 | grep MemTotal /proc/meminfo >> $LOG 61 | y=`grep MemTotal /proc/meminfo |awk '{ print $2 }'` 62 | mb="$(( $y / 1024 ))" 63 | gb="$(( $mb / 1024 ))" 64 | echo "RAM : $gb GB" >> $LOG 65 | 66 | ## Swap Information ## 67 | echo " " >> $LOG 68 | echo "## Swap Information" >> $LOG 69 | y1=$(free -k |grep Swap |awk '{print $2}') 70 | mb1="$(( $y1 / 1024 ))" 71 | gb1="$(( $mb1 / 1024 ))" 72 | echo "Swap Size: $gb1 GB" >> $LOG 73 | 74 | ## Disk Information ## 75 | echo " " >> $LOG 76 | echo "## Disk Information" >> $LOG 77 | lsblk |grep -E 'part|disk' $LOG 78 | 79 | ## LVM Information ## 80 | echo " " >> $LOG 81 | echo "## Physical Volumes" >> $LOG 82 | pvs >> $LOG 83 | 84 | echo " " >> $LOG 85 | echo "## Volume Groups" >> $LOG 86 | vgs >> $LOG 87 | 88 | echo " " >> $LOG 89 | echo "## Logical Volumes" >> $LOG 90 | lvs >> $LOG 91 | echo " " >> $LOG 92 | 93 | ## Partition Information ## 94 | echo "## DF Command Output" >> $LOG 95 | echo " " >> $LOG 96 | df -Ph -x tmpfs -x devtmpfs| sed s/%//g | awk '{ if($5 > 0) print $0;}' >> $LOG 97 | 98 | echo " " >> $LOG 99 | echo "## Port Information" >> $LOG 100 | ss -alntup |column -t |grep -E 'tcp|udp' >> $LOG 101 | 102 | echo " " >> $LOG 103 | echo "## Service Information" >> $LOG 104 | systemctl list-units --type=service --state=running |grep -vE 'systemd|selinux' >> $LOG 105 | 106 | echo " " >> $LOG 107 | echo "## Docker Containers" >> $LOG 108 | sudo docker ps -a >> $LOG 109 | 110 | echo " " >> $LOG 111 | echo "## DNS Server Details" >> $LOG 112 | cat /etc/resolv.conf >> $LOG 113 | 114 | echo "" >> $LOG 115 | echo "## Server Uptime" >> $LOG 116 | uptime >> $LOG 117 | 118 | sudo cp /tmp/asset/`hostname`.txt /Inventory/`hostname`-`date "+%Y-%m-%d"`.txt 119 | -------------------------------------------------------------------------------- /webserver_ubuntu.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################# 4 | # # 5 | # NOME: webserver_ubuntu.sh # 6 | # # 7 | # AUTOR: Amaury B. Souza (amaurybsouza@gmail.com) # 8 | # # 9 | # DESCRIÇÃO: O script faz a instalação da stack LAMP # 10 | # # 11 | # USO: ./webserver_ubuntu.sh # 12 | ############################################################# 13 | 14 | function menuprincipal () { 15 | clear 16 | echo " " 17 | echo LAMP Stack Ubuntu $0 18 | echo " " 19 | echo "Escolha uma opção abaixo para começar! 20 | 21 | 1 - Instalar Apache no sistema 22 | 2 - Instalar o banco de dados MariaDB no sistema 23 | 3 - Instalar o PHP7.2 no sistema 24 | 4 - Instalar a stack LAMP completa no sistema 25 | 0 - Sair do menu de instalação" 26 | echo " " 27 | echo -n "Opção escolhida: " 28 | read opcao 29 | case $opcao in 30 | 1) 31 | function apache () { 32 | TIME=2 33 | echo Atualizando seu sistema... 34 | sleep $TIME 35 | apt update && apt upgrade -y 36 | echo Iniciando a instalação do Apache no Ubuntu... 37 | sleep $TIME 38 | #sudo iptables -I INPUT -p tcp --dport 80 -j ACCEPT 39 | #sudo ufw allow http 40 | #sudo chown www-data:www-data /var/www/html/ -R 41 | apt install -y apache2 apache2-utils 42 | sudo systemctl start apache2 43 | sudo systemctl enable apache2 44 | echo " " 45 | if [ $? -eq 0 ] 46 | then 47 | echo O Apache foi instalado no seu sistema. 48 | else 49 | echo Ops, ocorreu algum erro, vamos tentar de novo! 50 | fi 51 | } 52 | apache 53 | read -n 1 -p " para menu principal" 54 | menuprincipal 55 | ;; 56 | 57 | 2) 58 | function maria () { 59 | TIME=2 60 | echo Iniciando a instalação do MariaDB... 61 | sleep $TIME 62 | sudo apt -y install mariadb-server mariadb-client 63 | sudo systemctl start mariadb 64 | sudo systemctl enable mariadb 65 | if [ $? -eq 0 ] 66 | then 67 | echo Agora vamos configurar o banco... 68 | sleep $TIME 69 | sudo mysql_secure_installation 70 | echo " " 71 | echo Opa, parabéns, o banco foi instalado e configurado! 72 | sleep $TIME 73 | else 74 | echo Ops, vamos resolver isso? Acho que deu errado. 75 | fi 76 | } 77 | maria 78 | read -n 1 -p " para menu principal" 79 | menuprincipal 80 | ;; 81 | 82 | 3) 83 | function php () { 84 | echo Iniciando a instalação do PHP... 85 | sudo apt install -y php7.2 libapache2-mod-php7.2 php7.2-mysql php-common php7.2-cli php7.2-common php7.2-json php7.2-opcache php7.2-readline 86 | sudo a2enmod php7.2 87 | sudo systemctl restart apache2 88 | echo " " 89 | echo O PHP 7.2 foi instalado, que legal! 90 | #Para testar o PHP instalado... 91 | #sudo vim /var/www/html/info.php 92 | } 93 | php 94 | read -n 1 -p " para menu principal" 95 | menuprincipal 96 | ;; 97 | 98 | 4) 99 | function lamp () { 100 | TIME=2 101 | #apache 102 | echo Vamos iniciar a instalação da stack LAMP no seu sistema... 103 | sleep $TIME 104 | echo Instalando o Apache... 105 | sleep $TIME 106 | apt install -y apache2 apache2-utils 107 | sudo systemctl start apache2 108 | sudo systemctl enable apache2 109 | echo Instalando o banco de dados... 110 | sleep $TIME 111 | #banco de dados 112 | sudo apt -y install mariadb-server mariadb-client 113 | sudo systemctl start mariadb 114 | sudo systemctl enable mariadb 115 | #PHP 116 | echo Instalando o PHP... 117 | sleep $TIME 118 | sudo apt install -y php7.2 libapache2-mod-php7.2 php7.2-mysql php-common php7.2-cli php7.2-common php7.2-json php7.2-opcache php7.2-readline 119 | sudo a2enmod php7.2 120 | sudo systemctl restart apache2 121 | echo Instalação concluída com êxito! 122 | sleep $TIME 123 | } 124 | lamp 125 | read -n 1 -p " para menu principal" 126 | menuprincipal 127 | ;; 128 | 129 | 0) 130 | function sair () { 131 | TIME=2 132 | echo " " 133 | echo Saindo do sistema... 134 | sleep $TIME 135 | exit 0 136 | } 137 | sair 138 | ;; 139 | 140 | esac 141 | } 142 | menuprincipal 143 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Shell Scripting Tutorial 2 | 3 | Keep in touch with for any kind of technical questions 4 | 5 | [Shell Scripting for Amazon Web Services to Manage it's resources](https://github.com/techtutorials/shell-scripting-tutorial/tree/FOTV/AWS) 6 | 7 | https://techtutorials.github.io/shell-scripting-tutorial/ 8 | 9 | * [Facebook](https://www.facebook.com/Linuxarkit/) 10 | * [Email List](https://feedburner.google.com/fb/a/mailverify?uri=arkit) 11 | * [Linkedin](https://in.linkedin.com/in/ravi-kumar-94530121) 12 | * [Twitter](https://twitter.com/aravikumar48) 13 | * [Youtube](https://www.youtube.com/Techarkit?sub_confirmation=1) 14 | * [Email Address](aravikumar48@gmail.com) 15 | * [WhatsApp Group](http://bit.ly/wappg) 16 | * [Linux Telegram Group](http://bit.ly/linux-telegram) 17 | * [Reddit TechTutorials](http://bit.ly/redditark) 18 | * [Tumblr](https://www.tumblr.com/blog/aravikumar48) 19 | 20 | A complete begineers guide to learn shell scripting from scratch which includes Videos, Practice scenarios and project idea. I will create one file for one topic with code. 21 | 22 | Before jumping into the Shell scripting below are commands you have to practice for better understanding and familiar with Linux command line interface. 23 | 24 | If you do not learn below commands also fine but i personally recommend you to learn commands first. 25 | 26 | [103 Linux Commands Video Tutorial](https://www.youtube.com/watch?v=VG-MMju9RhQ&list=PLHyfPDPl-JDX_dfDEpsvglu4x3h1RjPkz) 27 | 28 | alias and unalias, arch, arp, at, awk, bc, blkid, cal, cat, cd, chage, chattr, chgrp, chmod, chown, cp, cpio, crontab, curl, cut, date, dd, df, diff, dig, dnf, du, expr, fdisk, file, find, firewall-cmd, free, ftp, grep, head, history, hostname, id, ifconfig, iostat, ip, kill, last, lessandmore, ln, locate, lpstatandlpadmin, ls, lsof, lspci, mail, man, mdadm, mkdirandrmdir, mkisofs, mount, mutt, mv, nano, netstat, nice, renice, nslookup, passwd, pam_tally2, paste, ping, perloneliner, pkill, ps, pwd, reboot, poweroff, rm, rpm, rsync, scp, screen, sed, sort, ss, ssh, sysctl, tail, tar, tcpdump, top, touch, tr, traceroute, umask, uname, uniq, uptime, useradd, vi, vmstat, w, who, watch, wc, wget, ypcat, yppasswd, yum, zip, sar 29 | 30 | After that start learning shell scripting using below topics 31 | 32 | - [Shell Scripting Video Tutorial](https://www.youtube.com/watch?v=7GNUzvjS_mE&list=PL8cE5Nxf6M6b8qW7CSMsdKbEsPdG9pWfu) 33 | - [Shell Scripting course Overview](https://www.youtube.com/watch?v=7GNUzvjS_mE) 34 | - [Linux Basics](https://www.youtube.com/watch?v=IFvMor-0eFM) 35 | - [Linux Directory Structure](https://www.youtube.com/watch?v=rVxpe1_lNFE) 36 | - [Linux Basic Commands](https://www.youtube.com/watch?v=yYC8aaQ3eZA) 37 | - [Copy, Remove, Move and Time Commands](https://www.youtube.com/watch?v=G7XFreQkDB8) 38 | - [Dif and Grep Commands](https://www.youtube.com/watch?v=RwcQ6JzTsmA) 39 | - [Head, tail, sort and more commands](https://www.youtube.com/watch?v=OgV3qrPQulU) 40 | - [tr and wc commands](https://www.youtube.com/watch?v=d40a5zFa8yI) 41 | - [Disk utilities like fdisk, df and du commands](https://www.youtube.com/watch?v=vx1WZepOmKg) 42 | - [Getting Help From Command Line user Interface](https://www.youtube.com/watch?v=GcYu-0IIJas) 43 | - [w, who, hostnamem hostnamectl and uname commands](https://www.youtube.com/watch?v=7shAr5lp_Wc) 44 | - [Search for files and directories using find and locate commands](https://www.youtube.com/watch?v=Rd6e-OrsHpo) 45 | - [top command its output explanation](https://www.youtube.com/watch?v=UQ7rr4_47YY) 46 | - [vi & vim text editor](https://www.youtube.com/watch?v=K3SUrcJ740Y) 47 | - [sed, awk, vmstat and nestat commands](https://www.youtube.com/watch?v=4hJorSKg9E0) 48 | - [vnstat command](https://www.youtube.com/watch?v=KlpE2Ok6Bxo) 49 | - [Introduction to Graphical user interface](https://www.youtube.com/watch?v=Yck_xhz9ku0) 50 | - [cut command](https://www.youtube.com/watch?v=kBZNJdw7RQQ) 51 | - [Merge multiple files using paste command](https://www.youtube.com/watch?v=_Efd6PxhNq4) 52 | - [Connect and Manage remote machine using SSH](https://www.youtube.com/watch?v=Dp9J7aktYDs) 53 | - [Changing files and directory permissions](https://www.youtube.com/watch?v=NNAxqSyTsUI) 54 | - [tar and zip commands](https://www.youtube.com/watch?v=lVQppyhgERA) 55 | - [Scheduling future jobs using crontab](https://www.youtube.com/watch?v=OOOabNTnSwY) 56 | - [difference between scripting and programming](https://www.youtube.com/watch?v=5UuTNosxNgI) 57 | - [what is shell scripting and it's advantages](https://www.youtube.com/watch?v=m2DvuF_S4Ac) 58 | - [PATH environment variable](https://www.youtube.com/watch?v=4TZyWegxzGY) 59 | - [Symbols used shell scripting](https://www.youtube.com/watch?v=L8IxV7bvBHU) 60 | - [Make Shell Script Template](https://www.youtube.com/watch?v=7KEQJ7jtkTg) 61 | - [Quotes single, double and reverse - Know difference between each](https://www.youtube.com/watch?v=9_fhRI-dos4) 62 | - [Bash colors](https://arkit.co.in/coloring-style-text-shell-scripting/) 63 | - [Script exit status](https://arkit.co.in/shell-scripting-exit-status-shell-scripting-return-codes/) 64 | - [Variables and it's rules](https://www.youtube.com/watch?v=839s_OtTqDA) 65 | - [Special Variables](https://www.youtube.com/watch?v=PfxzX4XNYRE) 66 | - [Environment Variables, system variables and user defined variables](https://www.youtube.com/watch?v=PfxzX4XNYRE) 67 | - [Constant variables, Local & Global variables and Special variables](https://www.youtube.com/watch?v=839s_OtTqDA) 68 | - [Positional Parameters](https://www.youtube.com/watch?v=PfxzX4XNYRE) 69 | - [Count number command line arguments $#](https://www.youtube.com/watch?v=YizjrX9ph10) 70 | - [Arithmetic Operators](https://www.youtube.com/watch?v=qxNQ_D8txPo) 71 | - [Relational Operators](https://www.youtube.com/watch?v=U-u1wx5VeTU) 72 | - [LogicalOperators](https://www.youtube.com/watch?v=m_F1FTKdUU4) 73 | - [Boolean Operators](https://www.youtube.com/watch?v=U-u1wx5VeTU) 74 | - [Maths using expr command](https://www.youtube.com/watch?v=qxNQ_D8txPo) 75 | - [Real maths using bc command](https://www.youtube.com/watch?v=qxNQ_D8txPo) 76 | - [if statement](https://www.youtube.com/watch?v=gncu9vzmILw) 77 | - [if-else statement](https://www.youtube.com/watch?v=nDhbOeEQeNY) 78 | - [if-else-if statement](https://www.youtube.com/watch?v=UJET-9cmaqU) 79 | - [Nested if statement](https://www.youtube.com/watch?v=Kd1SJFnmj9k) 80 | - [Case statement](https://www.youtube.com/watch?v=JJ7mAPU0KhI) 81 | - [For Loop](https://www.youtube.com/watch?v=1fnAUUS4qg0) 82 | - [While Loop](https://www.youtube.com/watch?v=nBMuVIRGpwY) 83 | - [Until Loop](https://www.youtube.com/watch?v=zdk795qFgWk) 84 | - [Functions](https://www.youtube.com/watch?v=jXv1otUXMG4) 85 | - [Arrays](https://www.youtube.com/watch?v=2Fetj2V6rrM) 86 | - [Eval command](https://www.youtube.com/watch?v=AjqBRGwLmLc&list=PL8cE5Nxf6M6b8qW7CSMsdKbEsPdG9pWfu&index=57&t=0s) 87 | - [Shifting parameters using shift command](https://www.youtube.com/watch?v=48j0kxOFKZE) 88 | - [IFS - Input Field Separator](https://www.youtube.com/watch?v=so8IRuhWjEM) 89 | - [Writing CPU Usage script](https://www.youtube.com/watch?v=NQx43bY4lNo) 90 | - [Writing Disk Utilization script](https://www.youtube.com/watch?v=yXhdDV13nrA) 91 | - [Trouble shooting debugging shell scripts](https://www.youtube.com/watch?v=kgj-4_gmvi4) 92 | - [Checking shell script errors and improvements using shellcheck.net site](https://www.youtube.com/watch?v=kgj-4_gmvi4) 93 | - [Here Document to write paragraphs of text](https://www.youtube.com/watch?v=r9lb0ZxGFqE) 94 | - [Getopts Function](https://www.youtube.com/watch?v=j-lEoC0DWI8) 95 | - [Executing Multiple scripts from single script](https://youtu.be/hs-FK681D50) 96 | - [logger logging messages to log file](https://youtu.be/_kMXvtn1RRQ) 97 | 98 | **Resource to Download** 99 | 100 | - [Shell Scripting Book](https://arkit-in.tradepub.com/free/w_wile48/) 101 | - [Shell Scripting Book](https://arkit-in.tradepub.com/free/w_pack42/) 102 | - [Shell Scripting Book](https://arkit-in.tradepub.com/free/w_advb01/) 103 | - [Shell Scripting Book](https://arkit-in.tradepub.com/free/w_wile54/) 104 | 105 | **Write Your Own Method of Script for below Scenario** 106 | 107 | - **Scenario:** Everyday from Monday to Friday one directory will be created under /fullbackup/dailybackup/YYYY-MM-DD and it will move backup to its parent directory everyday midnight /fullbackup/archive/, However Saturday, Sunday and Monday directories will move to /fullbackup/archive path every monday evening. 108 | 109 | - **Directory Names Example:** 2018-12-24 2018-12-25 2018-12-26 2018-12-27 2018-12-28 110 | 111 | - **Question:** I would like to delete directories older than two days from /fullbackup/archive path. How do you do it using any scripting methods. 112 | 113 | - **Problem Statement:** I was trying to use ```find /path/ -type d -mtime +2 -print0 | xargs -r0 rm --```. This command does not work as expected due to directory modified date for SAT, SUN and MON moved directories same for all as Monday date. 114 | 115 | - **How Do you solve it.??** Write Shell Script to accomplish this task. Should run through crontab and clear directories older than two days. 116 | --------------------------------------------------------------------------------