├── .gitignore ├── Automation Scenarios that save effort ├── bulkfile.sh ├── chattr.sh ├── diskusage.sh ├── encryption.sh ├── logggingdeleteactions.sh ├── recoverrecycle.sh ├── recycle.sh ├── useradd.sh └── usercommandhistory.sh ├── Automation Scenarios that save time ├── BackupFolder │ └── Nishkarsh.tar ├── Scenario1.sh ├── Scenario10.sh ├── Scenario1213.sh ├── Scenario15.sh ├── Scenario16.sh ├── Scenario2.sh ├── Scenario45.sh ├── Scenario6.sh ├── Scenario7.sh ├── Scenario8.sh ├── Scenario9.sh ├── ScenariospreventingErrors │ ├── Sceario3.sh │ ├── Scenario1.sh │ └── Scenario2.sh └── del.log ├── CONTRIBUTING.md ├── Extra Scripts ├── DevOps-Sem3- Lab Scripts.rar └── DevOps-Sem3- Lab Scripts │ ├── 2.1 Introduction to Bash and Shell scripting │ ├── basicif.sh │ ├── forloop.sh │ ├── function.sh │ ├── hello.sh │ ├── input.sh │ ├── ladderif.sh │ ├── nestedif.sh │ ├── output.sh │ ├── switchcase.sh │ ├── variable.sh │ └── whileloop.sh │ ├── 2.2 Automation Scripts │ ├── 2.2.1 Automation Scripts that save Time and Effort │ │ ├── lab-A1.sh │ │ ├── lab-A10.sh │ │ ├── lab-A11.sh │ │ ├── lab-A12.sh │ │ ├── lab-A2.sh │ │ ├── lab-A3.sh │ │ ├── lab-A4.sh │ │ ├── lab-A5.sh │ │ ├── lab-A6.sh │ │ ├── lab-A7.sh │ │ ├── lab-A8.sh │ │ ├── lab-A9.sh │ │ ├── labA1.sh │ │ ├── labA10.sh │ │ ├── labA11.sh │ │ ├── labA12.sh │ │ ├── labA2.sh │ │ ├── labA3.sh │ │ ├── labA4.sh │ │ ├── labA5.sh │ │ ├── labA6.sh │ │ ├── labA7.sh │ │ ├── labA8.sh │ │ └── labA9.sh │ └── 2.2.2 Automation Scripts that prevent errors │ │ ├── lab-B1.sh │ │ ├── lab-B2.sh │ │ ├── lab-B3.sh │ │ ├── lab-B4.sh │ │ ├── lab-B5.sh │ │ ├── lab-B6.sh │ │ ├── labB1.sh │ │ ├── labB2.sh │ │ ├── labB3.sh │ │ ├── labB4.sh │ │ ├── labB5.sh │ │ └── labB6.sh │ ├── 2.4 Working with Make and Makefiles │ ├── 2.4.5.1 Basic Setup │ │ └── sourcecode │ │ │ ├── add.c │ │ │ ├── divide.c │ │ │ ├── main.c │ │ │ ├── multiply.c │ │ │ ├── mymath.h │ │ │ └── subtract.c │ ├── 2.4.5.2 Building binary from source code │ │ └── sourcecode │ │ │ ├── Makefile │ │ │ ├── add.c │ │ │ ├── divide.c │ │ │ ├── main.c │ │ │ ├── multiply.c │ │ │ ├── mymath.h │ │ │ └── subtract.c │ ├── 2.4.5.3 Transforming the Makefile to adhere to Best Practices │ │ └── sourcecode │ │ │ ├── Makefile │ │ │ ├── add.c │ │ │ ├── divide.c │ │ │ ├── main.c │ │ │ ├── multiply.c │ │ │ ├── mymath.h │ │ │ └── subtract.c │ ├── 2.4.5.4 Archiving logs with Make │ │ └── Makefile │ └── 2.4.5.5 Conditionals in Makefile │ │ └── sourcecode │ │ ├── add.c │ │ ├── divide.c │ │ ├── main.c │ │ ├── multiply.c │ │ ├── mymath.h │ │ ├── newmake.mk │ │ └── subtract.c │ └── 2.6 Creating reusable library scripts for automation scripts │ ├── 2.6.1.1 Formatting the Terminal │ ├── format.sh │ └── test.sh │ └── 2.6.1.2 Utilities library to reduce logic duplication │ ├── test.sh │ └── utils.sh ├── LICENSE ├── README.md ├── Shell Scripting Basics ├── Array Sorting.sh ├── Arrays.sh ├── Basic Script with User Input.sh ├── Calculator with Switch.sh ├── Call by reference.sh ├── Do While loop.sh ├── Else If.sh ├── For loop.sh ├── Function.sh ├── If Else Basics.sh ├── If Else.sh ├── README.md ├── RadixSort_Binaryconversion.sh ├── Standard Input Stream.sh ├── Standard Output and Standard Error Stream.sh ├── Swapping variables using Function.sh ├── Switch Basics.sh ├── Switch and Case.sh ├── User defined for loop.sh ├── While loop.sh ├── arraynew.sh ├── calbyrefcheck.sh ├── commandlineargumentsforscripts.sh ├── concatenation_script.sh ├── decimaltobinary.sh ├── elif.sh ├── function_basic.sh ├── if_script.sh ├── input.sh ├── log.tar ├── log.tar.gz ├── log_adduser.txt ├── log_basiccommands.txt ├── output.sh ├── read.txt └── variable.sh ├── Shell Scripting Tutorial ├── Automated_Backup │ ├── backup.sh │ ├── date_backup.sh │ ├── img │ │ ├── 1.Createbackupfolder.png │ │ ├── 2.CreateShellScript.png │ │ ├── 3.ShellScript.png │ │ ├── 4.Execute.png │ │ ├── 5.Output.png │ │ ├── 6.SettingCrontab.png │ │ ├── 7.crontab.png │ │ ├── Remove (1).png │ │ ├── Remove (2).png │ │ ├── date (1).png │ │ ├── date (2).png │ │ ├── multiple (1).png │ │ └── multiple (2).png │ ├── multiplebackup.sh │ └── remove_backup.sh ├── Basics │ ├── img │ │ ├── Arithmetic.png │ │ ├── Command Line Arguments.png │ │ ├── HelloWorld.png │ │ ├── Read.png │ │ ├── Special.png │ │ ├── Standard Inout.png │ │ ├── Unset.png │ │ └── Variable.png │ └── src │ │ ├── HelloWorld.sh │ │ ├── arithmetic.sh │ │ ├── commandlineargument.sh │ │ ├── deletevar.sh │ │ ├── inout.sh │ │ ├── readvar.sh │ │ ├── specialvar.sh │ │ └── variable.sh ├── Control Structures │ ├── img │ │ ├── case (1).png │ │ ├── case (2).png │ │ ├── elif (1).png │ │ ├── elif (2).png │ │ ├── if (1).png │ │ └── if (2).png │ └── src │ │ ├── if_elif_else.sh │ │ ├── if_else.sh │ │ └── switch_case.sh ├── Crontab Scheduler │ ├── README.md │ └── img │ │ ├── e.png │ │ ├── etc.png │ │ ├── etcron.png │ │ ├── extensions.png │ │ ├── l.png │ │ ├── r.png │ │ ├── u.png │ │ ├── var.png │ │ └── varcron.png ├── Functions │ ├── img │ │ ├── Scope (1).png │ │ ├── Scope (2).png │ │ ├── funct (1).png │ │ ├── funct (2).png │ │ ├── multicall3 (1).png │ │ ├── multicall3 (2).png │ │ ├── multiple (1).png │ │ ├── multiple (2).png │ │ ├── nested (1).png │ │ ├── nested (2).png │ │ ├── parameter (1).png │ │ ├── parameter (2).png │ │ ├── return (1).png │ │ ├── return (2).png │ │ ├── return1.png │ │ └── return2.png │ └── src │ │ ├── func_parameters.sh │ │ ├── function.sh │ │ ├── multicall.sh │ │ ├── multiplefunctioncall.sh │ │ ├── nestedfunction.sh │ │ ├── return_code.sh │ │ └── scope.sh ├── Looping in Shell Scripts │ ├── For loop │ │ ├── for_break.sh │ │ ├── for_continue.sh │ │ ├── for_ctype.sh │ │ ├── for_increment.sh │ │ ├── for_infinite.sh │ │ ├── for_items.sh │ │ ├── for_jump.sh │ │ ├── for_seq.sh │ │ └── forloop_tuple.sh │ ├── While loop │ │ ├── while_basics.sh │ │ └── while_infinite.sh │ └── img │ │ ├── For Loop │ │ ├── For Break.png │ │ ├── For continue.png │ │ ├── ForTuple.png │ │ ├── General For.png │ │ ├── Incrementfor.png │ │ ├── ctype for.png │ │ ├── for Infinite 1.png │ │ ├── for Infinite 2.png │ │ ├── forJump.png │ │ └── forseq.png │ │ └── While loop │ │ ├── While basics.png │ │ ├── infinite 1.png │ │ └── infinite 2.png └── tar_compression_tool │ ├── README.md │ ├── img │ ├── Multiple.png │ ├── append.png │ ├── compare.png │ ├── cvf.png │ ├── diff_create.png │ ├── diff_delete.png │ ├── diff_modify.png │ ├── diff_newfile.png │ ├── gz.png │ ├── list.png │ ├── shell.png │ ├── update.png │ ├── xgz.png │ └── xvf.png │ └── tar.sh └── _config.yml /.gitignore: -------------------------------------------------------------------------------- 1 | *.txt 2 | -------------------------------------------------------------------------------- /Automation Scenarios that save effort/bulkfile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | a=20 3 | while [ $a -lt 40 ] 4 | do 5 | wget "https://nptel.ac.in/courses/111104075/pdf/Module1/Lecture$a-Module1-Anova-1.pdf" 6 | a=$(($a+1)) 7 | done 8 | -------------------------------------------------------------------------------- /Automation Scenarios that save effort/chattr.sh: -------------------------------------------------------------------------------- 1 | #/bin/bash 2 | echo "List of folders available to change attribute for immuatability!" 3 | ls -ltu /home/ubuntu/Desktop/ 4 | read -p "Enter folder to make immuatable: " f 5 | sudo chattr +i $f 6 | echo "Folder made immutable" 7 | 8 | -------------------------------------------------------------------------------- /Automation Scenarios that save effort/diskusage.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | LIMIT='80' 3 | dir_name='/var' 4 | mailto="500060720@stu.upes.ac.in" 5 | subject="Disk Usage of $dir_name in Ubuntu" 6 | MAILX="mailx" 7 | which $MAILX > /dev/null 2>&1 8 | if [ $? -eq 0 ] 9 | then 10 | echo "Install mailx" 11 | exit 1 12 | fi 13 | cd $dir_name 14 | used=`df . | awk '{print $5}' | sed -ne 2p | cut -d"%" -f1` 15 | if [ $used -gt $LIMIT ] 16 | then 17 | du -sh ${dir_name}/* | $MAILX -s "$subject" "$mailto" 18 | fi 19 | -------------------------------------------------------------------------------- /Automation Scenarios that save effort/encryption.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | read -p "Enter the path of the folder to Encrypt: " f 3 | gpg -c $f 4 | echo "Folder encrypted!!" 5 | read -p "Do you want to decrypt now? " res 6 | case $res in 7 | y|Y|yes|YES) gpg -d $f.gpg ;; 8 | *) echo "Folder is still encrypted!!!" ;; 9 | esac 10 | -------------------------------------------------------------------------------- /Automation Scenarios that save effort/logggingdeleteactions.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | path=$1 3 | if [ -d $path ] 4 | then 5 | rm -r $path 6 | echo `date +%X` >> del.log 7 | echo ${whoami} >> del.log 8 | echo ${path} >> del.log 9 | fi 10 | if [ -f $path ] 11 | then 12 | rm -r $path 13 | echo `date +%X` >> del.log 14 | echo "$USER" >> del.log 15 | echo $path >> del.log 16 | fi 17 | -------------------------------------------------------------------------------- /Automation Scenarios that save effort/recoverrecycle.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash/ 2 | ls /home/ubuntu/Desktop/trashmine/ 3 | read -p "Enter which file or folder to delete: " file1 4 | read -p "Do you really want to recover? " res 5 | case $res in 6 | y|Y|yes|YES) 7 | read -p "Enter the path to send the recovered file: " p 8 | mv /home/ubuntu/Desktop/trashmine/$file1 $p ;; 9 | echo "Recovered the file!!!" 10 | *) ;; 11 | esac 12 | -------------------------------------------------------------------------------- /Automation Scenarios that save effort/recycle.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | read -p "Path to delete: " path 3 | ls -ltu $path 4 | path1="/home/ubuntu/Desktop/trashmine/" 5 | read -p "File to Delete: " file1 6 | echo "Do you want to delete?" 7 | read resp 8 | case $resp in 9 | y|Y|yes|YES|yes) 10 | if [ -e $file1 ] 11 | then 12 | mv $path/$file1 $path1 13 | else 14 | echo "File does not exist" 15 | fi 16 | ;; 17 | *) echo "not deleted" ;; 18 | esac 19 | -------------------------------------------------------------------------------- /Automation Scenarios that save effort/useradd.sh: -------------------------------------------------------------------------------- 1 | read -p "Enter the name of the user you want to create: " name 2 | adduser $name 3 | echo "User created" 4 | 5 | -------------------------------------------------------------------------------- /Automation Scenarios that save effort/usercommandhistory.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | read var 3 | if [ $(whoami) == "root" ] 4 | then 5 | echo " " 6 | else 7 | echo "Run as root" 8 | exit 9 | fi 10 | grep -n $var /home/*/.bash_history >> file.txt 11 | cat file.txt 12 | -------------------------------------------------------------------------------- /Automation Scenarios that save time/Scenario1.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | read -p "Filename of archive to be created: " f 3 | tar cvf $f.tar *.log 4 | du -sh $f.tar 5 | mv $f.tar /BackupFolder 6 | 7 | -------------------------------------------------------------------------------- /Automation Scenarios that save time/Scenario10.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | if [ $# -eq 0 ] 3 | then 4 | echo "No inputs send via command line!! Exiting" >&2; exit 1; 5 | fi 6 | path=$1 7 | path1="/home/ubuntu/Desktop/Automation-using-Shell-Scripts/ScenariosFullChapter2/" 8 | if [ -d $path ] 9 | then 10 | rm -r $path 11 | echo `date +%F` >> $path1/del.log 12 | echo "$whoami" >> $path1/del.log 13 | echo "$path" >> $path1/del.log 14 | fi 15 | if [ -f $path ] 16 | then 17 | rm $path 18 | echo `date +%F` >> $path1/del.log 19 | echo "$USERs" >> $path1/del.log 20 | echo "$path" >> $path1/del.log 21 | fi 22 | -------------------------------------------------------------------------------- /Automation Scenarios that save time/Scenario1213.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | read -p "Enter the path of the folder to Encrypt: " f 3 | gpg -c $f 4 | echo "Folder encrypted!!" 5 | read -p "Do you want to decrypt now? " res 6 | case $res in 7 | y|Y|yes|YES) gpg -d $f.gpg ;; 8 | *) echo "Folder is still encrypted!!!" ;; 9 | esac 10 | -------------------------------------------------------------------------------- /Automation Scenarios that save time/Scenario15.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | a=20 3 | while [ $a -lt 40 ] 4 | do 5 | wget "https://nptel.ac.in/courses/111104075/pdf/Module1/Lecture$a-Module1-Anova-1.pdf" 6 | a=$(($a+1)) 7 | done 8 | -------------------------------------------------------------------------------- /Automation Scenarios that save time/Scenario16.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo -e "\n\nUpdating Apt Packages and upgrading latest patches\n" 4 | sudo apt-get update -y && sudo apt-get upgrade -y 5 | 6 | echo -e "\n\nInstalling Apache2 Web server\n" 7 | sudo apt-get install apache2 apache2-doc apache2-mpm-prefork apache2-utils libexpat1 ssl-cert -y 8 | 9 | echo -e "\n\nInstalling PHP & Requirements\n" 10 | sudo apt-get install libapache2-mod-php7.0 php7.0 php7.0-common php7.0-curl php7.0-dev php7.0-gd php-pear php7.0-mcrypt php7.0-mysql -y 11 | 12 | echo -e "\n\nInstalling MySQL\n" 13 | sudo apt-get install mysql-server mysql-client -y 14 | 15 | echo -e "\n\nPermissions for /var/www\n" 16 | sudo chown -R www-data:www-data /var/www 17 | echo -e "\n\n Permissions have been set\n" 18 | 19 | echo -e "\n\nEnabling Modules\n" 20 | sudo a2enmod rewrite 21 | sudo phpenmod mcrypt 22 | 23 | echo -e "\n\nRestarting Apache\n" 24 | sudo service apache2 restart 25 | 26 | echo -e "\n\nLAMP Installation Completed" 27 | 28 | exit 0 29 | -------------------------------------------------------------------------------- /Automation Scenarios that save time/Scenario2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | find "/home/ubuntu/Desktop/Automation-using-Shell-Scripts/ScenariosFullChapter2/BackupFolder/" -type f -mtime +2 -exec rm {} \; 3 | -------------------------------------------------------------------------------- /Automation Scenarios that save time/Scenario45.sh: -------------------------------------------------------------------------------- 1 | backupfolder="/home/ubuntu/Desktop/Automation-using-Shell-Scripts/ScenariosFullChapter2/" 2 | find /var/log/apache2/ -mtime +1 -exec mv{} $backupfolder \; 3 | netstat -au 4 | netstat -lu 5 | -------------------------------------------------------------------------------- /Automation Scenarios that save time/Scenario6.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | read -p "Enter the username of the new user you want to create: " usr 3 | adduser $usr 4 | cd 5 | cd .. #Go to the absolute root 6 | sudo usermod -aG sudo $usr #Give user all the root permissions 7 | chmod 777 $usr #Give the user all rwx permissions 8 | read -p "Enter a group name for your user: " grp 9 | addgroup $grp 10 | sudo usermod -aG $grp $usr #add the user to the new group 11 | echo "The user has been created!!!!!" 12 | -------------------------------------------------------------------------------- /Automation Scenarios that save time/Scenario7.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | LIMIT='80' 3 | dir_name='/var' 4 | mailto="500060720@stu.upes.ac.in" 5 | subject="Disk Usage of $dir_name in Ubuntu" 6 | MAILX="mailx" 7 | which $MAILX > /dev/null 2>&1 8 | if [ $? -eq 0 ] 9 | then 10 | echo "Install mailx" 11 | exit 1 12 | fi 13 | cd $dir_name 14 | used=`df . | awk '{print $5}' | sed -ne 2p | cut -d"%" -f1` 15 | if [ $used -gt $LIMIT ] 16 | then 17 | du -sh ${dir_name}/* | $MAILX -s "$subject" "$mailto" 18 | fi 19 | -------------------------------------------------------------------------------- /Automation Scenarios that save time/Scenario8.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | read -p "Enter the path to delete files from: " path 3 | path1="/home/ubuntu/Desktop/Automation-using-Shell-Scripts/ScenariosFullChapter2/RecycleBin/" #RecycleBin Path 4 | echo "Following files are present on the path specified: " 5 | ls $path 6 | read -p "Enter the filename you want to delete: " f 7 | read -p "Do you really want to delete the file: " res 8 | case $res in 9 | y|Y|yes|YES) 10 | if [ -e $path/$f ] 11 | then 12 | mv $path/$f $path1 13 | else 14 | echo "File does not exist!!" 15 | fi 16 | ;; 17 | *) echo "File does not exist!!" 18 | ;; 19 | esac 20 | 21 | -------------------------------------------------------------------------------- /Automation Scenarios that save time/Scenario9.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | path1="/home/ubuntu/Desktop/Automation-using-Shell-Scripts/ScenariosFullChapter2/RecycleBin" 3 | echo "Following files are present on the Recycle Bin currently: " 4 | ls $path1 5 | read -p "Enter the filename you want to recover: " f 6 | read -p "Do you really want to recover? " resp 7 | case $resp in 8 | y|Y|YES|yes) 9 | read -p "Enter the Destination Path: " dest 10 | mv $path1/$f $dest 11 | echo "File recovered!!!" 12 | ;; 13 | *) echo "No files recovered!!" 14 | ;; 15 | esac 16 | -------------------------------------------------------------------------------- /Automation Scenarios that save time/ScenariospreventingErrors/Sceario3.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | read var 3 | if [ -z $var ] 4 | then 5 | read var 6 | fi 7 | compressed="$(echo $var | sed -e 's/[^[:alnum:]]'//g)" 8 | if [ $compressed != "$var" ] 9 | then 10 | echo "Input is not alphanumeric" 11 | else 12 | echo "Input is alphanumeric" 13 | fi 14 | 15 | -------------------------------------------------------------------------------- /Automation Scenarios that save time/ScenariospreventingErrors/Scenario1.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | read -p "Command to check which users have used: " var 3 | if [ $whoami == "root" ] 4 | then 5 | echo " " 6 | else 7 | echo "Run as root!!" 8 | exit 1 9 | fi 10 | grep -n $var /home/*/.bash_history >> /home/ubuntu/Desktop/Automation-using-Shell-Scripts/file.txt 11 | cat /home/ubuntu/Desktop/Automation-using-Shell-Scripts/file.txt 12 | -------------------------------------------------------------------------------- /Automation Scenarios that save time/ScenariospreventingErrors/Scenario2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | path="$1" 3 | a="$#" 4 | lastarg="${!a}" 5 | read -p "Search element: " ser 6 | read -p "Replace element: " rep 7 | if [ -d "$lastarg" ] 8 | then 9 | add=*.txt 10 | else 11 | if [ -f "$lastarg" ] 12 | then 13 | add="$lastarg" 14 | else 15 | echo "Invalid path" 16 | fi 17 | fi 18 | sed -i -e -w 's/'"$ser"'/'"$rep"'/g' $add 19 | 20 | -------------------------------------------------------------------------------- /Automation Scenarios that save time/del.log: -------------------------------------------------------------------------------- 1 | 2018-11-18 2 | 3 | /home/ubuntu/Desktop/nishkarsh 4 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to Collaborate: 2 | 3 | 1. Fork the repository to your own GitHub account. 4 | 5 | 2. Clone the repository to your local machine 6 | ``` 7 | $ git clone "https://www.github.com/{Username}/Automation-using-Shell-Scripts" 8 | ``` 9 | where username is your GitHub account username. 10 | 11 | 3. Create a branch where you can do your local work. 12 | Never work on **master** branch as we do not allow master commits except by admins. 13 | ``` 14 | $ git branch {branchname} 15 | $ git checkout branchname 16 | ``` 17 | 18 | 4. Do your work and stage your changes. 19 | ``` 20 | $ git add 21 | ``` 22 | 23 | 5. Commit you changes with a commit message containing your name, file(s) worked upon, changes added. 24 | ``` 25 | $ git commit -m "Name| files| Changes" 26 | ``` 27 | 28 | 6. Push changes to your forked repository 29 | ``` 30 | $ git push -u origin branchname 31 | ``` 32 | 7. Create a pull request to the upstream repository. 33 | 34 | # Synchronize forked repository with Upstream repository 35 | 36 | 1. Create upstream as our repository 37 | ``` 38 | $ git remote add upstream "https://www.github.com/NishkarshRaj/Automation-using-Shell-Scripts" 39 | ``` 40 | 41 | 2. Fetch upstream changes in local machine 42 | ``` 43 | $ git fetch upstream 44 | ``` 45 | 46 | 3. Switch to master branch 47 | ``` 48 | $ git checkout master 49 | ``` 50 | 51 | 4. Merge changes in local machine 52 | ``` 53 | $ git merge upstream/master 54 | ``` 55 | 56 | 5. Push changes to your forked GitHub repository 57 | ``` 58 | $ git push -f origin master 59 | ``` 60 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Extra Scripts/DevOps-Sem3- Lab Scripts.rar -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.1 Introduction to Bash and Shell scripting/basicif.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Initializing variables with a value 4 | number1=5; number2=5 5 | 6 | # Expression "[ $number1 -eq $number2 ]" that resolves to a Boolean value. 7 | if [ $number1 -eq $number2 ]; then 8 | # Code to run if condition is true 9 | echo "$number1 is equal to $number2" 10 | else 11 | # Code to run if condition is false 12 | echo "$number1 is not equal to $number2" 13 | fi 14 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.1 Introduction to Bash and Shell scripting/forloop.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Loop through the items delimited by whitespace in the "names" variable. 4 | names="Name1 Name2 Name3" 5 | 6 | for name in $names; do 7 | echo "Hello $name" 8 | done 9 | 10 | # Loop through the items in the substituted sequence command. 11 | for number in `seq 1 10`; do 12 | echo "I am $number" 13 | done 14 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.1 Introduction to Bash and Shell scripting/function.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Defining the function "greet" that accepts a parameter 4 | function greet { 5 | echo "Hello $1!" 6 | } 7 | 8 | # Calling the function "greet" with parameter "World" 9 | greet "World" 10 | 11 | # Calling the function "greet" with parameter "User" 12 | greet "User" 13 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.1 Introduction to Bash and Shell scripting/hello.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Creating a readonly variable called "greeting" 4 | readonly greeting="Hello" 5 | 6 | # Creating an ordinary variable called "current_time" 7 | current_time=`date +%X` 8 | 9 | # Substitute the output of the command "whoami". 10 | echo "Hi, I am $(whoami)." 11 | 12 | # Prompt the user to provide their name 13 | read -e -p "Who are you? " myName 14 | 15 | # Substituting the variables and printing them 16 | echo "${greeting:-Hi}, $myName. Now the time is $current_time" 17 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.1 Introduction to Bash and Shell scripting/input.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Reading the text from stdin and assigning it to the variable named "myName" 4 | read myName 5 | 6 | # Substitute the variable and print the text 7 | echo "Hello ${myName}" 8 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.1 Introduction to Bash and Shell scripting/ladderif.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Initializing variables with a value 4 | number1=5; number2=5 5 | 6 | # Evaluating the expression 7 | if [ $number1 -gt $number2 ]; then 8 | echo "$number1 is greater than $number2" 9 | elif [ $number1 -lt $number2 ]; then 10 | echo "$number1 is lesser than $number2" 11 | else 12 | echo "$number1 is equal to $number2" 13 | fi 14 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.1 Introduction to Bash and Shell scripting/nestedif.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Initializing variables with a value 4 | number1=5; number2=5 5 | 6 | # Evaluating the expression 7 | if [ $number1 -ne $number2 ]; then 8 | if [ $number1 -gt $number2 ]; then 9 | echo "$number1 is greater than $number2" 10 | else 11 | echo "$number1 is lesser than $number2" 12 | fi 13 | else 14 | echo "$number1 is equal to $number2" 15 | fi 16 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.1 Introduction to Bash and Shell scripting/output.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Send the text to the stdout 4 | echo "any standard text can be here" 5 | 6 | # Send the text to the stderr 7 | echo "any error text can be here" >&2 8 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.1 Introduction to Bash and Shell scripting/switchcase.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | name="john" 4 | 5 | # A string is given as input to case statement. 6 | case "$name" in 7 | 8 | # Checks for the switch that matches and executes that action. 9 | john) echo "Welcome Admin" ;; 10 | alexa) echo "Welcome User" ;; 11 | 12 | # If none is matched, "*" switch gets executed. 13 | *) echo "Access Denied" ;; 14 | esac -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.1 Introduction to Bash and Shell scripting/variable.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Assigning the text "User!" to the variable 4 | myName="User!" 5 | 6 | # Substituting it by enclosing the variable name in ${} 7 | echo "Hello ${myName}" 8 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.1 Introduction to Bash and Shell scripting/whileloop.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | count="9" 4 | 5 | # Evaluates whether "count" is greater than zero and if true, enters loop. 6 | while [ $count -gt 0 ]; do 7 | 8 | # Print the "count" 9 | echo "$count" 10 | 11 | # Decrease the value of count 12 | count=$[$count-1] 13 | done 14 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.2 Automation Scripts/2.2.1 Automation Scripts that save Time and Effort/lab-A1.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | read -e -p "Log Directory: " log_directory 4 | 5 | read -e -p "File Extension: " extension 6 | 7 | read -e -p "Backup Directory: " backup_directory 8 | 9 | tar czf archive.tar.gz $(find $log_directory -name "*.$extension") 10 | 11 | mv archive.tar.gz $backup_directory/$(date +%F).tar.gz 12 | 13 | rm $(find $log_directory -name "*.$extension") 14 | 15 | exit 0 16 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.2 Automation Scripts/2.2.1 Automation Scripts that save Time and Effort/lab-A10.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | removelog="/var/log/remove.log" 4 | 5 | if [ $# -eq 0 ] ; then 6 | echo "Usage: $0 [-s] list of files or directories"; exit 0; 7 | fi 8 | 9 | if [ "$1" = "-s" ] ; then 10 | shift 11 | else 12 | echo "$(date): ${USER}: $@" >> $removelog 13 | fi 14 | 15 | /bin/rm "$@" 16 | 17 | exit 0 18 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.2 Automation Scripts/2.2.1 Automation Scripts that save Time and Effort/lab-A11.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | downloads_directory="$HOME/Downloads" 4 | 5 | if [ -z "$1" ]; then 6 | echo "ERROR: Download List file is not specified in the arguments" >&2; exit 1; 7 | fi 8 | 9 | if ! [ -z "$2" ]; then 10 | downloads_directory=$2 11 | fi 12 | 13 | if [ ! -d $downloads_directory ] ; then 14 | mkdir -p $downloads_directory 15 | fi 16 | 17 | 18 | download_list=$1 19 | 20 | cat $download_list | while read url; do 21 | echo "----------------------------------------------------------------------------------------------------" 22 | echo "$url" 23 | wget -P $downloads_directory $url 24 | done 25 | 26 | exit 0 27 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.2 Automation Scripts/2.2.1 Automation Scripts that save Time and Effort/lab-A12.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo -e "\n\nUpdating Apt Packages and upgrading latest patches\n" 4 | sudo apt-get update -y && sudo apt-get upgrade -y 5 | 6 | echo -e "\n\nInstalling Apache2 Web server\n" 7 | sudo apt-get install apache2 apache2-doc apache2-mpm-prefork apache2-utils libexpat1 ssl-cert -y 8 | 9 | echo -e "\n\nInstalling PHP & Requirements\n" 10 | sudo apt-get install libapache2-mod-php7.0 php7.0 php7.0-common php7.0-curl php7.0-dev php7.0-gd php-pear php7.0-mcrypt php7.0-mysql -y 11 | 12 | echo -e "\n\nInstalling MySQL\n" 13 | sudo apt-get install mysql-server mysql-client -y 14 | 15 | echo -e "\n\nPermissions for /var/www\n" 16 | sudo chown -R www-data:www-data /var/www 17 | echo -e "\n\n Permissions have been set\n" 18 | 19 | echo -e "\n\nEnabling Modules\n" 20 | sudo a2enmod rewrite 21 | sudo phpenmod mcrypt 22 | 23 | echo -e "\n\nRestarting Apache\n" 24 | sudo service apache2 restart 25 | 26 | echo -e "\n\nLAMP Installation Completed" 27 | 28 | exit 0 29 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.2 Automation Scripts/2.2.1 Automation Scripts that save Time and Effort/lab-A2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ -z "$1" ]; then 4 | echo "ERROR: No argument supplied" >&2; exit 1; 5 | fi 6 | 7 | archives_directory=$(realpath $1) 8 | if [ ! -d "$archives_directory" ]; then 9 | echo "ERROR: Archives directory does not exist" >&2; exit 1; 10 | fi 11 | 12 | find $archives_directory -type f -name '*.tar.gz' -mmin +$((60 * 24 * 2)) -exec rm {} \; 13 | 14 | path_to_script=$(realpath "$0") 15 | if ! (crontab -l | grep -Fxq "0 0 * * * $path_to_script $archives_directory"); then 16 | crontab -l | { cat; echo "0 0 * * * $path_to_script $archives_directory"; } | crontab - 17 | echo "Script added to Cron" 18 | fi 19 | 20 | exit 0 21 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.2 Automation Scripts/2.2.1 Automation Scripts that save Time and Effort/lab-A3.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ -z "$1" ]; then 4 | echo "ERROR: Credentials file not specified" >&2; exit 1; 5 | elif [ -z "$2" ]; then 6 | echo "ERROR: Backup directory not specified" >&2; exit 1; 7 | fi 8 | 9 | credentials_file=$(realpath $1) 10 | backup_directory=$(realpath $2) 11 | if [ ! -f "$credentials_file" ]; then 12 | echo "ERROR: Credentials file does not exist" >&2; exit 1; 13 | elif [ ! -d "$backup_directory" ]; then 14 | echo "ERROR: Backup directory does not exist" >&2; exit 1; 15 | fi 16 | 17 | source $credentials_file 18 | 19 | if [ -z ${hostname:+word} ]; then 20 | echo "ERROR: hostname is not set" >&2; exit 1; 21 | elif [ -z ${username:+word} ]; then 22 | echo "ERROR: username is not set" >&2; exit 1; 23 | elif [ -z ${password:+word} ]; then 24 | echo "ERROR: password is not set" >&2; exit 1; 25 | fi 26 | 27 | mysqldump -h$hostname -u$username -p$password --all-databases > backup.sql 28 | if [[ $? != 0 ]]; then 29 | echo "ERROR: Error in taking mysql backup" >&2; exit 1; 30 | fi 31 | 32 | mv backup.sql $backup_directory/$(date +%F_%R).sql 33 | 34 | path_to_script=$(realpath "$0") 35 | if ! (crontab -l | grep -Fxq "0 */12 * * * $path_to_script $credentials_file $backup_directory"); then 36 | crontab -l | { cat; echo "0 */12 * * * $path_to_script $credentials_file $backup_directory"; } | crontab - 37 | echo "Script added to Cron" 38 | fi 39 | 40 | exit 0 41 | 42 | # 43 | # Credentials File 44 | # 45 | # hostname=localhost 46 | # username=root 47 | # password=password 48 | # -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.2 Automation Scripts/2.2.1 Automation Scripts that save Time and Effort/lab-A4.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ -z "$1" ]; then 4 | echo "ERROR: Location of the web server's log is not specified" >&2; exit 1; 5 | fi 6 | 7 | log_file=$(realpath $1) 8 | email_id=admin@example.com 9 | 10 | if [ ! -f "$log_file" ]; then 11 | echo "ERROR: Log file does not exist" >&2; exit 1; 12 | fi 13 | 14 | ( 15 | echo -e 'Apache Web Server Access Logs - Summary\n' 16 | echo -e 'STATUS\t\t-\tCOUNT' 17 | cat $log_file | sed 's/.*HTTP\/1\.1\" \(...\).*/\1/g' | sort | uniq -c | awk '{printf " %s\t\t-\t %s\n", $2, $1}' 18 | echo -e '\nIP ADDRESS\t-\tHITS' 19 | cat $log_file | sed 's/ .*//g' | sort | uniq -c | awk '{printf "%s\t-\t %s\n", $2, $1}' 20 | ) > /tmp/log_summary 21 | 22 | 23 | cat /tmp/log_summary | mail -s "Apache Web Server Access Logs - Summary" $email_id 24 | if [[ $? != 0 ]]; then 25 | echo "ERROR: Error in sending email to $email" >&2; exit 1; 26 | fi 27 | 28 | path_to_script=$(realpath "$0") 29 | if ! (crontab -l | grep -Fxq "0 * * * * $path_to_script $log_file"); then 30 | crontab -l | { cat; echo "0 * * * * $path_to_script $log_file"; } | crontab - 31 | echo "Script added to Cron" 32 | fi 33 | 34 | exit 0 35 | # MailUtils should be configured -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.2 Automation Scripts/2.2.1 Automation Scripts that save Time and Effort/lab-A5.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ -z "$1" ]; then 4 | echo "ERROR: Webserver's port is not specified in the arguments" >&2; exit 1; 5 | fi 6 | 7 | listening_port=$1 8 | 9 | netstat -lnt | grep -q ":$1 " 10 | 11 | if [[ $? != 0 ]]; then 12 | echo "ERROR: Web server is not running"; 13 | /etc/init.d/apache2 restart 14 | fi 15 | 16 | path_to_script=$(realpath "$0") 17 | if ! (crontab -l | grep -Fxq "*/1 * * * * $path_to_script $listening_port"); then 18 | crontab -l | { cat; echo "*/1 * * * * $path_to_script $listening_port"; } | crontab - 19 | echo "Script added to Cron" 20 | fi 21 | 22 | exit 0 23 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.2 Automation Scripts/2.2.1 Automation Scripts that save Time and Effort/lab-A6.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [[ $(id -u) -ne 0 ]] ; then 4 | echo "ERROR: Please run as root." ; exit 1 ; 5 | fi 6 | 7 | if [ ! -f "/opt/forbidden_commands.txt" ]; then 8 | echo "ERROR: The file /root/forbidden_commands.txt does not exist" >&2; exit 1; 9 | fi 10 | 11 | for user in $(getent passwd | cut -d : -f 6 | grep '/home' | sed 's:$:/.bashrc:'); do 12 | cat $user | grep -q 'validate_commands' 13 | if [[ $? != 0 ]]; then 14 | echo ' 15 | function validate_commands { 16 | cat /opt/forbidden_commands.txt | while read command; do 17 | if [ "$BASH_COMMAND" == "$command" ]; then 18 | echo "Sorry! \"$BASH_COMMAND\" cannot be executed"; 19 | exit 1; 20 | fi 21 | done 22 | } 23 | trap validate_commands DEBUG' >> $user 24 | fi 25 | done 26 | 27 | exit 0 28 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.2 Automation Scripts/2.2.1 Automation Scripts that save Time and Effort/lab-A7.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ -z "$1" ]; then 4 | echo "ERROR: The Device name is not specified in the arguments" >&2; exit 1; 5 | elif [ -z "$2" ]; then 6 | echo "ERROR: The thresold limit is not specified in the arguments" >&2; exit 1; 7 | fi 8 | 9 | device_name=$1 10 | thresold_limit=$2 11 | email_id=admin@example.com 12 | 13 | percentage_used=$(df -H | grep "$device_name" | awk '{ print $5 }' | cut -d'%' -f1) 14 | 15 | if [ $percentage_used -ge $thresold_limit ]; then 16 | echo "Running out of space \"$device_name ($percentage_used%)\" on $(hostname) as on $(date)" | 17 | mail -s "Disk usage breached the thresold limit" $email_id 18 | fi 19 | 20 | path_to_script=$(realpath "$0") 21 | if ! (crontab -l | grep -Fxq "*/1 * * * * $path_to_script $device_name $thresold_limit"); then 22 | crontab -l | { cat; echo "*/1 * * * * $path_to_script $device_name $thresold_limit"; } | crontab - 23 | echo "Script added to Cron" 24 | fi 25 | 26 | exit 0 27 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.2 Automation Scripts/2.2.1 Automation Scripts that save Time and Effort/lab-A8.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | recycle_bin="$HOME/.recycle_bin" 4 | rm="/bin/rm -r " 5 | copy="/bin/cp -r " 6 | 7 | if [ $# -eq 0 ] ; then 8 | echo "ERROR: Please enter the file path to delete." >&2; exit 1; 9 | fi 10 | 11 | 12 | flags="" 13 | 14 | while getopts "dfiPRrvW" args; do 15 | case $args in 16 | f ) exec $rm "$@" ;; 17 | * ) flags="$flags -$args" ;; 18 | esac 19 | done 20 | shift $(( $OPTIND - 1 )) 21 | 22 | if [ ! -d $recycle_bin ] ; then 23 | mkdir $recycle_bin 24 | fi 25 | 26 | for arg; do 27 | newname="$recycle_bin/$(date "+%S.%M.%H.%d.%m").$(basename "$arg")" 28 | if [ -f "$arg" ] ; then 29 | $copy "$arg" "$newname" 30 | elif [ -d "$arg" ] ; then 31 | $copy "$arg" "$newname" 32 | fi 33 | done 34 | 35 | exec $rm $flags "$@" 36 | 37 | exit 0 38 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.2 Automation Scripts/2.2.1 Automation Scripts that save Time and Effort/lab-A9.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | recycle_bin="$HOME/.recycle_bin" 4 | rm="/bin/rm" 5 | move="/bin/mv" 6 | 7 | destination=$(pwd) 8 | 9 | if [ ! -d $recycle_bin ] ; then 10 | echo "ERROR: Recycle Bin directory was not found in your home directory" >&2 ; exit 1; 11 | fi 12 | 13 | cd $recycle_bin 14 | 15 | if [ $# -eq 0 ] ; then 16 | echo "Deleted files in the recycle bin:" 17 | ls -FC | sed -e 's/\([[:digit:]][[:digit:]]\.\)\{5\}//g' -e 's/^/ /' 18 | exit 0 19 | fi 20 | 21 | pattern_matches="$(ls *"$1" 2> /dev/null | wc -l)" 22 | 23 | if [ $pattern_matches -eq 0 ] ; then 24 | echo "ERROR: No match for the pattern \"$1\" in the recycle bin" >&2; exit 1; 25 | fi 26 | 27 | if [ $pattern_matches -gt 1 ] ; then 28 | echo "More than one file or directory match in the archive:" 29 | index=1 30 | for name in $(ls -td *"$1"); do 31 | datetime="$(echo $name | cut -c1-14| awk -F. '{ print $5"/"$4" at "$3":"$2":"$1 }')" 32 | if [ -d $name ] ; then 33 | size="$(ls $name | wc -l | sed 's/[^0-9]//g')" 34 | echo " $index) $1 (contents = ${size} items, deleted = $datetime)" 35 | else 36 | size="$(ls -sdk1 $name | awk '{print $1}')" 37 | echo " $index) $1 (size = ${size}Kb, deleted = $datetime)" 38 | fi 39 | index=$(( $index + 1)) 40 | done 41 | 42 | echo "" 43 | read -e -p "Which version of $1 do you want to restore ('0' to quit)? [1] : " desired 44 | 45 | if [ ${desired:=1} -ge $index ] ; then 46 | echo "ERROR: Restore cancelled by user: index value too big." >&2; exit 1; 47 | fi 48 | 49 | if [ $desired -lt 1 ] ; then 50 | echo "ERROR: Restore cancelled by user." >&2 ; exit 1; 51 | fi 52 | 53 | restore="$(ls -td1 *"$1" | sed -n "${desired}p")" 54 | if [ -e "$destination/$1" ] ; then 55 | echo "ERROR: Already exists in this directory. Cannot overwrite." >&2; exit 1; 56 | fi 57 | 58 | echo -n "Restoring file \"$1\" ..." 59 | $move "$restore" "$destination/$1" 60 | echo "done." 61 | 62 | read -e -p "Delete the additional copies of this file? [y] " answer 63 | 64 | if [ ${answer:=y} = "y" ] ; then 65 | $rm -rf *"$1" 66 | echo "deleted." 67 | else 68 | echo "additional copies retained." 69 | fi 70 | else 71 | if [ -e "$destination/$1" ] ; then 72 | echo "ERROR: Already exists in this directory. Cannot overwrite." >&2; exit 1; 73 | fi 74 | 75 | restore="$(ls -d *"$1")" 76 | 77 | echo -n "Restoring file \"$1\" ... " 78 | $move "$restore" "$destination/$1" 79 | echo "done." 80 | fi 81 | 82 | exit 0 83 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.2 Automation Scripts/2.2.1 Automation Scripts that save Time and Effort/labA1.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | read -e -p "Log Directory: " log_directory 4 | 5 | read -e -p "File Extension: " extension 6 | 7 | read -e -p "Backup Directory: " backup_directory 8 | 9 | tar czf archive.tar.gz $(find $log_directory -name "*.$extension") 10 | 11 | mv archive.tar.gz $backup_directory/$(date +%F).tar.gz 12 | 13 | rm $(find $log_directory -name "*.$extension") 14 | 15 | exit 0 16 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.2 Automation Scripts/2.2.1 Automation Scripts that save Time and Effort/labA10.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | removelog="/var/log/remove.log" 4 | 5 | if [ $# -eq 0 ] ; then 6 | echo "Usage: $0 [-s] list of files or directories"; exit 0; 7 | fi 8 | 9 | if [ "$1" = "-s" ] ; then 10 | shift 11 | else 12 | echo "$(date): ${USER}: $@" >> $removelog 13 | fi 14 | 15 | /bin/rm "$@" 16 | 17 | exit 0 18 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.2 Automation Scripts/2.2.1 Automation Scripts that save Time and Effort/labA11.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | downloads_directory="$HOME/Downloads" 4 | 5 | if [ -z "$1" ]; then 6 | echo "ERROR: Download List file is not specified in the arguments" >&2; exit 1; 7 | fi 8 | 9 | if ! [ -z "$2" ]; then 10 | downloads_directory=$2 11 | fi 12 | 13 | if [ ! -d $downloads_directory ] ; then 14 | mkdir -p $downloads_directory 15 | fi 16 | 17 | 18 | download_list=$1 19 | 20 | cat $download_list | while read url; do 21 | echo "----------------------------------------------------------------------------------------------------" 22 | echo "$url" 23 | wget -P $downloads_directory $url 24 | done 25 | 26 | exit 0 27 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.2 Automation Scripts/2.2.1 Automation Scripts that save Time and Effort/labA12.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo -e "\n\nUpdating Apt Packages and upgrading latest patches\n" 4 | sudo apt-get update -y && sudo apt-get upgrade -y 5 | 6 | echo -e "\n\nInstalling Apache2 Web server\n" 7 | sudo apt-get install apache2 apache2-doc apache2-mpm-prefork apache2-utils libexpat1 ssl-cert -y 8 | 9 | echo -e "\n\nInstalling PHP & Requirements\n" 10 | sudo apt-get install libapache2-mod-php7.0 php7.0 php7.0-common php7.0-curl php7.0-dev php7.0-gd php-pear php7.0-mcrypt php7.0-mysql -y 11 | 12 | echo -e "\n\nInstalling MySQL\n" 13 | sudo apt-get install mysql-server mysql-client -y 14 | 15 | echo -e "\n\nPermissions for /var/www\n" 16 | sudo chown -R www-data:www-data /var/www 17 | echo -e "\n\n Permissions have been set\n" 18 | 19 | echo -e "\n\nEnabling Modules\n" 20 | sudo a2enmod rewrite 21 | sudo phpenmod mcrypt 22 | 23 | echo -e "\n\nRestarting Apache\n" 24 | sudo service apache2 restart 25 | 26 | echo -e "\n\nLAMP Installation Completed" 27 | 28 | exit 0 29 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.2 Automation Scripts/2.2.1 Automation Scripts that save Time and Effort/labA2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ -z "$1" ]; then 4 | echo "ERROR: No argument supplied" >&2; exit 1; 5 | fi 6 | 7 | archives_directory=$(realpath $1) 8 | if [ ! -d "$archives_directory" ]; then 9 | echo "ERROR: Archives directory does not exist" >&2; exit 1; 10 | fi 11 | 12 | find $archives_directory -type f -name '*.tar.gz' -mmin +$((60 * 24 * 2)) -exec rm {} \; 13 | 14 | path_to_script=$(realpath "$0") 15 | if ! (crontab -l | grep -Fxq "0 0 * * * $path_to_script $archives_directory"); then 16 | crontab -l | { cat; echo "0 0 * * * $path_to_script $archives_directory"; } | crontab - 17 | echo "Script added to Cron" 18 | fi 19 | 20 | exit 0 21 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.2 Automation Scripts/2.2.1 Automation Scripts that save Time and Effort/labA3.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ -z "$1" ]; then 4 | echo "ERROR: Credentials file not specified" >&2; exit 1; 5 | elif [ -z "$2" ]; then 6 | echo "ERROR: Backup directory not specified" >&2; exit 1; 7 | fi 8 | 9 | credentials_file=$(realpath $1) 10 | backup_directory=$(realpath $2) 11 | if [ ! -f "$credentials_file" ]; then 12 | echo "ERROR: Credentials file does not exist" >&2; exit 1; 13 | elif [ ! -d "$backup_directory" ]; then 14 | echo "ERROR: Backup directory does not exist" >&2; exit 1; 15 | fi 16 | 17 | source $credentials_file 18 | 19 | if [ -z ${hostname:+word} ]; then 20 | echo "ERROR: hostname is not set" >&2; exit 1; 21 | elif [ -z ${username:+word} ]; then 22 | echo "ERROR: username is not set" >&2; exit 1; 23 | elif [ -z ${password:+word} ]; then 24 | echo "ERROR: password is not set" >&2; exit 1; 25 | fi 26 | 27 | mysqldump -h$hostname -u$username -p$password --all-databases > backup.sql 28 | if [[ $? != 0 ]]; then 29 | echo "ERROR: Error in taking mysql backup" >&2; exit 1; 30 | fi 31 | 32 | mv backup.sql $backup_directory/$(date +%F_%R).sql 33 | 34 | path_to_script=$(realpath "$0") 35 | if ! (crontab -l | grep -Fxq "0 */12 * * * $path_to_script $credentials_file $backup_directory"); then 36 | crontab -l | { cat; echo "0 */12 * * * $path_to_script $credentials_file $backup_directory"; } | crontab - 37 | echo "Script added to Cron" 38 | fi 39 | 40 | exit 0 41 | 42 | # 43 | # Credentials File 44 | # 45 | # hostname=localhost 46 | # username=root 47 | # password=password 48 | # -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.2 Automation Scripts/2.2.1 Automation Scripts that save Time and Effort/labA4.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ -z "$1" ]; then 4 | echo "ERROR: Location of the web server's log is not specified" >&2; exit 1; 5 | fi 6 | 7 | log_file=$(realpath $1) 8 | email_id=admin@example.com 9 | 10 | if [ ! -f "$log_file" ]; then 11 | echo "ERROR: Log file does not exist" >&2; exit 1; 12 | fi 13 | 14 | ( 15 | echo -e 'Apache Web Server Access Logs - Summary\n' 16 | echo -e 'STATUS\t\t-\tCOUNT' 17 | cat $log_file | sed 's/.*HTTP\/1\.1\" \(...\).*/\1/g' | sort | uniq -c | awk '{printf " %s\t\t-\t %s\n", $2, $1}' 18 | echo -e '\nIP ADDRESS\t-\tHITS' 19 | cat $log_file | sed 's/ .*//g' | sort | uniq -c | awk '{printf "%s\t-\t %s\n", $2, $1}' 20 | ) > /tmp/log_summary 21 | 22 | 23 | cat /tmp/log_summary | mail -s "Apache Web Server Access Logs - Summary" $email_id 24 | if [[ $? != 0 ]]; then 25 | echo "ERROR: Error in sending email to $email" >&2; exit 1; 26 | fi 27 | 28 | path_to_script=$(realpath "$0") 29 | if ! (crontab -l | grep -Fxq "0 * * * * $path_to_script $log_file"); then 30 | crontab -l | { cat; echo "0 * * * * $path_to_script $log_file"; } | crontab - 31 | echo "Script added to Cron" 32 | fi 33 | 34 | exit 0 35 | # MailUtils should be configured -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.2 Automation Scripts/2.2.1 Automation Scripts that save Time and Effort/labA5.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ -z "$1" ]; then 4 | echo "ERROR: Webserver's port is not specified in the arguments" >&2; exit 1; 5 | fi 6 | 7 | listening_port=$1 8 | 9 | netstat -lnt | grep -q ":$1 " 10 | 11 | if [[ $? != 0 ]]; then 12 | echo "ERROR: Web server is not running"; 13 | /etc/init.d/apache2 restart 14 | fi 15 | 16 | path_to_script=$(realpath "$0") 17 | if ! (crontab -l | grep -Fxq "*/1 * * * * $path_to_script $listening_port"); then 18 | crontab -l | { cat; echo "*/1 * * * * $path_to_script $listening_port"; } | crontab - 19 | echo "Script added to Cron" 20 | fi 21 | 22 | exit 0 23 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.2 Automation Scripts/2.2.1 Automation Scripts that save Time and Effort/labA6.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [[ $(id -u) -ne 0 ]] ; then 4 | echo "ERROR: Please run as root." ; exit 1 ; 5 | fi 6 | 7 | if [ ! -f "/opt/forbidden_commands.txt" ]; then 8 | echo "ERROR: The file /root/forbidden_commands.txt does not exist" >&2; exit 1; 9 | fi 10 | 11 | for user in $(getent passwd | cut -d : -f 6 | grep '/home' | sed 's:$:/.bashrc:'); do 12 | cat $user | grep -q 'validate_commands' 13 | if [[ $? != 0 ]]; then 14 | 15 | function validate_commands { 16 | cat /opt/forbidden_commands.txt | while read command; do 17 | if [ "$BASH_COMMAND" == "$command" ]; then 18 | echo "Sorry! \"$BASH_COMMAND\" cannot be executed"; 19 | exit 1; 20 | fi 21 | done 22 | } 23 | trap validate_commands DEBUG >> $user 24 | fi 25 | done 26 | 27 | exit 0 28 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.2 Automation Scripts/2.2.1 Automation Scripts that save Time and Effort/labA7.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ -z "$1" ]; then 4 | echo "ERROR: The Device name is not specified in the arguments" >&2; exit 1; 5 | elif [ -z "$2" ]; then 6 | echo "ERROR: The thresold limit is not specified in the arguments" >&2; exit 1; 7 | fi 8 | 9 | device_name=$1 10 | thresold_limit=$2 11 | email_id=admin@example.com 12 | 13 | percentage_used=$(df -H | grep "$device_name" | awk '{ print $5 }' | cut -d'%' -f1) 14 | 15 | if [ $percentage_used -ge $thresold_limit ]; then 16 | echo "Running out of space \"$device_name ($percentage_used%)\" on $(hostname) as on $(date)" | 17 | mail -s "Disk usage breached the thresold limit" $email_id 18 | fi 19 | 20 | path_to_script=$(realpath "$0") 21 | if ! (crontab -l | grep -Fxq "*/1 * * * * $path_to_script $device_name $thresold_limit"); then 22 | crontab -l | { cat; echo "*/1 * * * * $path_to_script $device_name $thresold_limit"; } | crontab - 23 | echo "Script added to Cron" 24 | fi 25 | 26 | exit 0 27 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.2 Automation Scripts/2.2.1 Automation Scripts that save Time and Effort/labA8.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | recycle_bin="$HOME/.recycle_bin" 4 | rm="/bin/rm -r " 5 | copy="/bin/cp -r " 6 | 7 | if [ $# -eq 0 ] ; then 8 | echo "ERROR: Please enter the file path to delete." >&2; exit 1; 9 | fi 10 | 11 | 12 | flags="" 13 | 14 | while getopts "dfiPRrvW" args; do 15 | case $args in 16 | f ) exec $rm "$@" ;; 17 | * ) flags="$flags -$args" ;; 18 | esac 19 | done 20 | shift $(( $OPTIND - 1 )) 21 | 22 | if [ ! -d $recycle_bin ] ; then 23 | mkdir $recycle_bin 24 | fi 25 | 26 | for arg; do 27 | newname="$recycle_bin/$(date "+%S.%M.%H.%d.%m").$(basename "$arg")" 28 | if [ -f "$arg" ] ; then 29 | $copy "$arg" "$newname" 30 | elif [ -d "$arg" ] ; then 31 | $copy "$arg" "$newname" 32 | fi 33 | done 34 | 35 | exec $rm $flags "$@" 36 | 37 | exit 0 38 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.2 Automation Scripts/2.2.1 Automation Scripts that save Time and Effort/labA9.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | recycle_bin="$HOME/.recycle_bin" 4 | rm="/bin/rm" 5 | move="/bin/mv" 6 | 7 | destination=$(pwd) 8 | 9 | if [ ! -d $recycle_bin ] ; then 10 | echo "ERROR: Recycle Bin directory was not found in your home directory" >&2 ; exit 1; 11 | fi 12 | 13 | cd $recycle_bin 14 | 15 | if [ $# -eq 0 ] ; then 16 | echo "Deleted files in the recycle bin:" 17 | ls -FC | sed -e 's/\([[:digit:]][[:digit:]]\.\)\{5\}//g' -e 's/^/ /' 18 | exit 0 19 | fi 20 | 21 | pattern_matches="$(ls *"$1" 2> /dev/null | wc -l)" 22 | 23 | if [ $pattern_matches -eq 0 ] ; then 24 | echo "ERROR: No match for the pattern \"$1\" in the recycle bin" >&2; exit 1; 25 | fi 26 | 27 | if [ $pattern_matches -gt 1 ] ; then 28 | echo "More than one file or directory match in the archive:" 29 | index=1 30 | for name in $(ls -td *"$1"); do 31 | datetime="$(echo $name | cut -c1-14| awk -F. '{ print $5"/"$4" at "$3":"$2":"$1 }')" 32 | if [ -d $name ] ; then 33 | size="$(ls $name | wc -l | sed 's/[^0-9]//g')" 34 | echo " $index) $1 (contents = ${size} items, deleted = $datetime)" 35 | else 36 | size="$(ls -sdk1 $name | awk '{print $1}')" 37 | echo " $index) $1 (size = ${size}Kb, deleted = $datetime)" 38 | fi 39 | index=$(( $index + 1)) 40 | done 41 | 42 | echo "" 43 | read -e -p "Which version of $1 do you want to restore ('0' to quit)? [1] : " desired 44 | 45 | if [ ${desired:=1} -ge $index ] ; then 46 | echo "ERROR: Restore cancelled by user: index value too big." >&2; exit 1; 47 | fi 48 | 49 | if [ $desired -lt 1 ] ; then 50 | echo "ERROR: Restore cancelled by user." >&2 ; exit 1; 51 | fi 52 | 53 | restore="$(ls -td1 *"$1" | sed -n "${desired}p")" 54 | if [ -e "$destination/$1" ] ; then 55 | echo "ERROR: Already exists in this directory. Cannot overwrite." >&2; exit 1; 56 | fi 57 | 58 | echo -n "Restoring file \"$1\" ..." 59 | $move "$restore" "$destination/$1" 60 | echo "done." 61 | 62 | read -e -p "Delete the additional copies of this file? [y] " answer 63 | 64 | if [ ${answer:=y} = "y" ] ; then 65 | $rm -rf *"$1" 66 | echo "deleted." 67 | else 68 | echo "additional copies retained." 69 | fi 70 | else 71 | if [ -e "$destination/$1" ] ; then 72 | echo "ERROR: Already exists in this directory. Cannot overwrite." >&2; exit 1; 73 | fi 74 | 75 | restore="$(ls -d *"$1")" 76 | 77 | echo -n "Restoring file \"$1\" ... " 78 | $move "$restore" "$destination/$1" 79 | echo "done." 80 | fi 81 | 82 | exit 0 83 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.2 Automation Scripts/2.2.2 Automation Scripts that prevent errors/lab-B1.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [[ $(id -u) -ne 0 ]] ; then 4 | echo "ERROR: Please run as root." ; exit 1 ; 5 | fi 6 | 7 | if [ -z "$1" ]; then 8 | echo "ERROR: Search pattern not specified" >&2; exit 1; 9 | fi 10 | 11 | pattern=$1 12 | 13 | getent passwd | cut -d : -f 6 | sed 's:$:/.bash_history:' | xargs -d '\n' grep -s -n -e "$pattern" > /tmp/search 14 | cat /tmp/search | sed 's/.*\/\(.*\)\/\.bash_history\:\(.*\)\:/\1 \t \2 \t/g' 15 | 16 | exit 0 17 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.2 Automation Scripts/2.2.2 Automation Scripts that prevent errors/lab-B2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ "$#" -eq 0 ]; then 4 | echo "ERROR: Files/Folders to search & replace is not specified" >&2; exit 1; 5 | fi 6 | 7 | item_paths="" 8 | for i in $@; do 9 | item_path=$(realpath $i) 10 | if [ -f "$item_path" ]; then 11 | item_paths+="$item_path " 12 | elif [ -d "$item_path" ]; then 13 | item_paths+="$item_path/* " 14 | else 15 | echo "ERROR: The given path \"$item_path\" is not a suitable type" >&2; exit 1; 16 | fi 17 | done 18 | 19 | read -e -p "Search For: " search_text 20 | read -e -p "Replace With: " replace_text 21 | 22 | sed -i "s/$search_text/$replace_text/g" $(grep -lz "$search_text" $item_paths) 23 | 24 | exit 0 25 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.2 Automation Scripts/2.2.2 Automation Scripts that prevent errors/lab-B3.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | is_valid_alpha_numeric_text() 4 | { 5 | filtered_input="$(echo $1 | sed -e 's/[^[:alnum:]]//g')" 6 | 7 | if [ "$filtered_input" == "$1" ] ; then 8 | return 0 9 | else 10 | return 1 11 | fi 12 | } 13 | 14 | read -e -p "Enter Input to validate: " input_text 15 | 16 | if [[ "$input_text" == '' ]]; then 17 | echo "ERROR: Please enter any text to validate." >&2; exit 1; 18 | fi 19 | 20 | if ! is_valid_alpha_numeric_text "$input_text" ; then 21 | echo "Input contains characters other than alphabets and numbers" 22 | else 23 | echo "Input is absolutely valid." 24 | fi 25 | 26 | exit 0 27 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.2 Automation Scripts/2.2.2 Automation Scripts that prevent errors/lab-B4.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ "$#" != "2" ]; then 4 | ( echo " 5 | Usage: `basename $0` 6 | 7 | Truncate the to exactly bytes. 8 | * If doesn't exist it is created. 9 | * is a number which can be optionally followed by K, M, G, etc." ) >&2; exit 1; 10 | fi 11 | 12 | size=$1 13 | file="$2" 14 | 15 | dd bs=1 seek=$size if=/dev/null of="$file" 16 | 17 | exit 0 18 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.2 Automation Scripts/2.2.2 Automation Scripts that prevent errors/lab-B5.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ "$#" -ne "2" ]; then 4 | echo "ERROR: Two files/directories must be passed as arguments" >&2; exit 1; 5 | fi 6 | 7 | removed=$(echo -en '\033[31m') 8 | added=$(echo -en '\033[32m') 9 | changed=$(echo -en '\033[34m') 10 | file=$(echo -en '\033[47m') 11 | reset=$(echo -en '\033[0m') 12 | 13 | diff -Naru "$@" | sed " 14 | s/^\*\{3\}.*\*\{4\}/$changed&$reset/;t 15 | s/^-\{3\}.*-\{4\}/$changed&$reset/;t 16 | s/^@.*/$changed&$reset/;t 17 | s/^[0-9].*/$changed&$reset/;t 18 | s/^!.*/$changed&$reset/;t 19 | 20 | s/^-.*/$removed&$reset/;t 21 | s/^<.*/$removed&$reset/;t 22 | 23 | s/^\*.*/$added&$reset/;t 24 | s/^\+.*/$added&$reset/;t 25 | s/^>.*/$added&$reset/;t 26 | 27 | s/^Only in.*/$file&$reset/;t 28 | s/^Index: .*/$file&$reset/;t 29 | s/^diff .*/$file&$reset/;t 30 | " 31 | 32 | exit 0 33 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.2 Automation Scripts/2.2.2 Automation Scripts that prevent errors/lab-B6.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | first_letter_uppercase() { 4 | echo $1 | awk '{print toupper(substr($0,0,1))tolower(substr($0,2))}' 5 | } 6 | 7 | everything_uppercase() { 8 | echo $1 | awk '{print toupper($0)}' 9 | } 10 | 11 | everything_lowercase() { 12 | echo $1 | awk '{print tolower($0)}' 13 | } 14 | 15 | if [ -z "$1" ]; then 16 | echo "ERROR: Input text is not supplied in the arguments" >&2; exit 1; 17 | fi 18 | 19 | input=$1 20 | 21 | echo " 22 | First Letter Capital: $(first_letter_uppercase "$input") 23 | Uppercase: $(everything_uppercase "$input") 24 | Lowercase: $(everything_lowercase "$input") 25 | " 26 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.2 Automation Scripts/2.2.2 Automation Scripts that prevent errors/labB1.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [[ $(id -u) -ne 0 ]] ; then 4 | echo "ERROR: Please run as root." ; exit 1 ; 5 | fi 6 | 7 | if [ -z "$1" ]; then 8 | echo "ERROR: Search pattern not specified" >&2; exit 1; 9 | fi 10 | 11 | pattern=$1 12 | 13 | getent passwd | cut -d : -f 6 | sed 's:$:/.bash_history:' | xargs -d '\n' grep -s -n -e "$pattern" > /tmp/search 14 | cat /tmp/search | sed 's/.*\/\(.*\)\/\.bash_history\:\(.*\)\:/\1 \t \2 \t/g' 15 | 16 | exit 0 17 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.2 Automation Scripts/2.2.2 Automation Scripts that prevent errors/labB2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ "$#" -eq 0 ]; then 4 | echo "ERROR: Files/Folders to search & replace is not specified" >&2; exit 1; 5 | fi 6 | 7 | item_paths="" 8 | for i in $@; do 9 | item_path=$(realpath $i) 10 | if [ -f "$item_path" ]; then 11 | item_paths+="$item_path " 12 | elif [ -d "$item_path" ]; then 13 | item_paths+="$item_path/* " 14 | else 15 | echo "ERROR: The given path \"$item_path\" is not a suitable type" >&2; exit 1; 16 | fi 17 | done 18 | 19 | read -e -p "Search For: " search_text 20 | read -e -p "Replace With: " replace_text 21 | 22 | sed -i "s/$search_text/$replace_text/g" $(grep -lz "$search_text" $item_paths) 23 | 24 | exit 0 25 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.2 Automation Scripts/2.2.2 Automation Scripts that prevent errors/labB3.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | is_valid_alpha_numeric_text() 4 | { 5 | filtered_input="$(echo $1 | sed -e 's/[^[:alnum:]]//g')" 6 | 7 | if [ "$filtered_input" == "$1" ] ; then 8 | return 0 9 | else 10 | return 1 11 | fi 12 | } 13 | 14 | read -e -p "Enter Input to validate: " input_text 15 | 16 | if [[ "$input_text" == '' ]]; then 17 | echo "ERROR: Please enter any text to validate." >&2; exit 1; 18 | fi 19 | 20 | if ! is_valid_alpha_numeric_text "$input_text" ; then 21 | echo "Input contains characters other than alphabets and numbers" 22 | else 23 | echo "Input is absolutely valid." 24 | fi 25 | 26 | exit 0 27 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.2 Automation Scripts/2.2.2 Automation Scripts that prevent errors/labB4.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ "$#" != "2" ]; then 4 | ( echo " 5 | Usage: `basename $0` 6 | 7 | Truncate the to exactly bytes. 8 | * If doesn't exist it is created. 9 | * is a number which can be optionally followed by K, M, G, etc." ) >&2; exit 1; 10 | fi 11 | 12 | size=$1 13 | file="$2" 14 | 15 | dd bs=1 seek=$size if=/dev/null of="$file" 16 | 17 | exit 0 18 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.2 Automation Scripts/2.2.2 Automation Scripts that prevent errors/labB5.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ "$#" -ne "2" ]; then 4 | echo "ERROR: Two files/directories must be passed as arguments" >&2; exit 1; 5 | fi 6 | 7 | removed=$(echo -en '\033[31m') 8 | added=$(echo -en '\033[32m') 9 | changed=$(echo -en '\033[34m') 10 | file=$(echo -en '\033[47m') 11 | reset=$(echo -en '\033[0m') 12 | 13 | diff -Naru "$@" | sed " 14 | s/^\*\{3\}.*\*\{4\}/$changed&$reset/;t 15 | s/^-\{3\}.*-\{4\}/$changed&$reset/;t 16 | s/^@.*/$changed&$reset/;t 17 | s/^[0-9].*/$changed&$reset/;t 18 | s/^!.*/$changed&$reset/;t 19 | 20 | s/^-.*/$removed&$reset/;t 21 | s/^<.*/$removed&$reset/;t 22 | 23 | s/^\*.*/$added&$reset/;t 24 | s/^\+.*/$added&$reset/;t 25 | s/^>.*/$added&$reset/;t 26 | 27 | s/^Only in.*/$file&$reset/;t 28 | s/^Index: .*/$file&$reset/;t 29 | s/^diff .*/$file&$reset/;t 30 | " 31 | 32 | exit 0 33 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.2 Automation Scripts/2.2.2 Automation Scripts that prevent errors/labB6.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | first_letter_uppercase() { 4 | echo $1 | awk '{print toupper(substr($0,0,1))tolower(substr($0,2))}' 5 | } 6 | 7 | everything_uppercase() { 8 | echo $1 | awk '{print toupper($0)}' 9 | } 10 | 11 | everything_lowercase() { 12 | echo $1 | awk '{print tolower($0)}' 13 | } 14 | 15 | if [ -z "$1" ]; then 16 | echo "ERROR: Input text is not supplied in the arguments" >&2; exit 1; 17 | fi 18 | 19 | input=$1 20 | 21 | echo " 22 | First Letter Capital: $(first_letter_uppercase "$input") 23 | Uppercase: $(everything_uppercase "$input") 24 | Lowercase: $(everything_lowercase "$input") 25 | " 26 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.4 Working with Make and Makefiles/2.4.5.1 Basic Setup/sourcecode/add.c: -------------------------------------------------------------------------------- 1 | #include "mymath.h" 2 | 3 | int add(int a, int b) { 4 | return a + b; 5 | } 6 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.4 Working with Make and Makefiles/2.4.5.1 Basic Setup/sourcecode/divide.c: -------------------------------------------------------------------------------- 1 | #include "mymath.h" 2 | 3 | int divide(int a, int b) { 4 | return a / b; 5 | } 6 | 7 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.4 Working with Make and Makefiles/2.4.5.1 Basic Setup/sourcecode/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "mymath.h" 3 | 4 | int main() { 5 | int a, b; 6 | printf("Hello World\n\n"); 7 | 8 | printf("Enter Two Numbers(A B): "); 9 | scanf("%d %d", &a, &b); 10 | 11 | printf("Addition: %d\n", add(a, b)); 12 | printf("Subtraction: %d\n", subtract(a, b)); 13 | printf("Multiplication: %d\n", multiply(a, b)); 14 | printf("Division: %d\n\n", divide(a, b)); 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.4 Working with Make and Makefiles/2.4.5.1 Basic Setup/sourcecode/multiply.c: -------------------------------------------------------------------------------- 1 | #include "mymath.h" 2 | 3 | int multiply(int a, int b) { 4 | return a * b; 5 | } 6 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.4 Working with Make and Makefiles/2.4.5.1 Basic Setup/sourcecode/mymath.h: -------------------------------------------------------------------------------- 1 | int add(int a, int b); 2 | int subtract(int a, int b); 3 | int multiply(int a, int b); 4 | int divide(int a, int b); 5 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.4 Working with Make and Makefiles/2.4.5.1 Basic Setup/sourcecode/subtract.c: -------------------------------------------------------------------------------- 1 | #include "mymath.h" 2 | 3 | int subtract(int a, int b) { 4 | return a - b; 5 | } 6 | 7 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.4 Working with Make and Makefiles/2.4.5.2 Building binary from source code/sourcecode/Makefile: -------------------------------------------------------------------------------- 1 | 2 | mycalculator: main.c mymath.h add.c subtract.c multiply.c divide.c 3 | gcc -o mycalculator main.c mymath.h add.c subtract.c multiply.c divide.c 4 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.4 Working with Make and Makefiles/2.4.5.2 Building binary from source code/sourcecode/add.c: -------------------------------------------------------------------------------- 1 | #include "mymath.h" 2 | 3 | int add(int a, int b) { 4 | return a + b; 5 | } 6 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.4 Working with Make and Makefiles/2.4.5.2 Building binary from source code/sourcecode/divide.c: -------------------------------------------------------------------------------- 1 | #include "mymath.h" 2 | 3 | int divide(int a, int b) { 4 | return a / b; 5 | } 6 | 7 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.4 Working with Make and Makefiles/2.4.5.2 Building binary from source code/sourcecode/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "mymath.h" 3 | 4 | int main() { 5 | int a, b; 6 | printf("Hello World\n\n"); 7 | 8 | printf("Enter Two Numbers(A B): "); 9 | scanf("%d %d", &a, &b); 10 | 11 | printf("Addition: %d\n", add(a, b)); 12 | printf("Subtraction: %d\n", subtract(a, b)); 13 | printf("Multiplication: %d\n", multiply(a, b)); 14 | printf("Division: %d\n\n", divide(a, b)); 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.4 Working with Make and Makefiles/2.4.5.2 Building binary from source code/sourcecode/multiply.c: -------------------------------------------------------------------------------- 1 | #include "mymath.h" 2 | 3 | int multiply(int a, int b) { 4 | return a * b; 5 | } 6 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.4 Working with Make and Makefiles/2.4.5.2 Building binary from source code/sourcecode/mymath.h: -------------------------------------------------------------------------------- 1 | int add(int a, int b); 2 | int subtract(int a, int b); 3 | int multiply(int a, int b); 4 | int divide(int a, int b); 5 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.4 Working with Make and Makefiles/2.4.5.2 Building binary from source code/sourcecode/subtract.c: -------------------------------------------------------------------------------- 1 | #include "mymath.h" 2 | 3 | int subtract(int a, int b) { 4 | return a - b; 5 | } 6 | 7 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.4 Working with Make and Makefiles/2.4.5.3 Transforming the Makefile to adhere to Best Practices/sourcecode/Makefile: -------------------------------------------------------------------------------- 1 | 2 | INCL = mymath.h 3 | SRC = main.c add.c subtract.c multiply.c divide.c 4 | OBJ = $(SRC:.c=.o) 5 | EXE = mycalculator 6 | 7 | # Compiler, Linker Defines 8 | CC = /usr/bin/gcc 9 | CFLAGS = -ansi -pedantic -Wall -O2 10 | LIBPATH = -L. 11 | LDFLAGS = -o $(EXE) $(LIBPATH) $(LIBS) 12 | CFDEBUG = -ansi -pedantic -Wall -g -DDEBUG $(LDFLAGS) 13 | RM = /bin/rm -f 14 | 15 | # Compile and Assemble C Source Files into Object Files 16 | %.o: %.c 17 | $(CC) -c $(CFLAGS) $*.c 18 | 19 | # Link all Object Files with external Libraries into Binaries 20 | $(EXE): $(OBJ) 21 | $(CC) $(LDFLAGS) $(OBJ) 22 | 23 | # Objects depend on these Libraries 24 | $(OBJ): $(INCL) 25 | 26 | # Create a gdb/dbx Capable Executable with DEBUG flags turned on 27 | debug: 28 | $(CC) $(CFDEBUG) $(SRC) 29 | 30 | # Clean Up Objects, Exectuables, Dumps out of source directory 31 | clean: 32 | $(RM) $(OBJ) $(EXE) core a.out 33 | 34 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.4 Working with Make and Makefiles/2.4.5.3 Transforming the Makefile to adhere to Best Practices/sourcecode/add.c: -------------------------------------------------------------------------------- 1 | #include "mymath.h" 2 | 3 | int add(int a, int b) { 4 | return a + b; 5 | } 6 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.4 Working with Make and Makefiles/2.4.5.3 Transforming the Makefile to adhere to Best Practices/sourcecode/divide.c: -------------------------------------------------------------------------------- 1 | #include "mymath.h" 2 | 3 | int divide(int a, int b) { 4 | return a / b; 5 | } 6 | 7 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.4 Working with Make and Makefiles/2.4.5.3 Transforming the Makefile to adhere to Best Practices/sourcecode/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "mymath.h" 3 | 4 | int main() { 5 | int a, b; 6 | printf("Hello World\n\n"); 7 | 8 | printf("Enter Two Numbers(A B): "); 9 | scanf("%d %d", &a, &b); 10 | 11 | printf("Addition: %d\n", add(a, b)); 12 | printf("Subtraction: %d\n", subtract(a, b)); 13 | printf("Multiplication: %d\n", multiply(a, b)); 14 | printf("Division: %d\n\n", divide(a, b)); 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.4 Working with Make and Makefiles/2.4.5.3 Transforming the Makefile to adhere to Best Practices/sourcecode/multiply.c: -------------------------------------------------------------------------------- 1 | #include "mymath.h" 2 | 3 | int multiply(int a, int b) { 4 | return a * b; 5 | } 6 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.4 Working with Make and Makefiles/2.4.5.3 Transforming the Makefile to adhere to Best Practices/sourcecode/mymath.h: -------------------------------------------------------------------------------- 1 | int add(int a, int b); 2 | int subtract(int a, int b); 3 | int multiply(int a, int b); 4 | int divide(int a, int b); 5 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.4 Working with Make and Makefiles/2.4.5.3 Transforming the Makefile to adhere to Best Practices/sourcecode/subtract.c: -------------------------------------------------------------------------------- 1 | #include "mymath.h" 2 | 3 | int subtract(int a, int b) { 4 | return a - b; 5 | } 6 | 7 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.4 Working with Make and Makefiles/2.4.5.4 Archiving logs with Make/Makefile: -------------------------------------------------------------------------------- 1 | 2 | SHELL = /bin/bash 3 | LOGDIR = /var/log 4 | LOGEXT = log 5 | BACKUPDIR = /archives 6 | 7 | start: createarchive movearchive deletelogs 8 | echo "Logs files are archived and deleted" 9 | 10 | createarchive: 11 | tar czf archive.tar.gz $(shell find $(LOGDIR) -name "*.$(LOGEXT)") 12 | 13 | movearchive: 14 | mv archive.tar.gz $(BACKUPDIR)/$(shell date +%F).tar.gz 15 | 16 | deletelogs: 17 | rm $(shell find $(LOGDIR) -name "*.$(LOGEXT)") 18 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.4 Working with Make and Makefiles/2.4.5.5 Conditionals in Makefile/sourcecode/add.c: -------------------------------------------------------------------------------- 1 | #include "mymath.h" 2 | 3 | int add(int a, int b) { 4 | return a + b; 5 | } 6 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.4 Working with Make and Makefiles/2.4.5.5 Conditionals in Makefile/sourcecode/divide.c: -------------------------------------------------------------------------------- 1 | #include "mymath.h" 2 | 3 | int divide(int a, int b) { 4 | return a / b; 5 | } 6 | 7 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.4 Working with Make and Makefiles/2.4.5.5 Conditionals in Makefile/sourcecode/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "mymath.h" 3 | 4 | int main() { 5 | int a, b; 6 | printf("Hello World\n\n"); 7 | 8 | printf("Enter Two Numbers(A B): "); 9 | scanf("%d %d", &a, &b); 10 | 11 | printf("Addition: %d\n", add(a, b)); 12 | printf("Subtraction: %d\n", subtract(a, b)); 13 | printf("Multiplication: %d\n", multiply(a, b)); 14 | printf("Division: %d\n\n", divide(a, b)); 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.4 Working with Make and Makefiles/2.4.5.5 Conditionals in Makefile/sourcecode/multiply.c: -------------------------------------------------------------------------------- 1 | #include "mymath.h" 2 | 3 | int multiply(int a, int b) { 4 | return a * b; 5 | } 6 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.4 Working with Make and Makefiles/2.4.5.5 Conditionals in Makefile/sourcecode/mymath.h: -------------------------------------------------------------------------------- 1 | int add(int a, int b); 2 | int subtract(int a, int b); 3 | int multiply(int a, int b); 4 | int divide(int a, int b); 5 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.4 Working with Make and Makefiles/2.4.5.5 Conditionals in Makefile/sourcecode/newmake.mk: -------------------------------------------------------------------------------- 1 | 2 | DEBUG = False 3 | SHELL = /bin/bash 4 | CC = /usr/bin/gcc 5 | OBJECTS = main.o add.o subtract.o multiply.o divide.o 6 | 7 | ifeq ($(DEBUG),True) 8 | CFLAG = -Wall -g 9 | else 10 | CFLAG = 11 | endif 12 | 13 | mycalculator: ${OBJECTS} 14 | ${CC} ${CFLAG} -o $@ ${OBJECTS} 15 | 16 | %.o : %.c 17 | ${CC} ${CFLAG} -o $@ -c $< 18 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.4 Working with Make and Makefiles/2.4.5.5 Conditionals in Makefile/sourcecode/subtract.c: -------------------------------------------------------------------------------- 1 | #include "mymath.h" 2 | 3 | int subtract(int a, int b) { 4 | return a - b; 5 | } 6 | 7 | -------------------------------------------------------------------------------- /Extra Scripts/DevOps-Sem3- Lab Scripts/2.6 Creating reusable library scripts for automation scripts/2.6.1.1 Formatting the Terminal/format.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | style() { 4 | echo "\033[$1m" 5 | } 6 | 7 | red_text() { printf "$(style "31")$1$(style "0")"; } 8 | green_text() { printf "$(style "32")$1$(style "0")"; } 9 | yellow_text() { printf "$(style "33")$1$(style "0")"; } 10 | blue_text() { printf "$(style "34")$1$(style "0")"; } 11 | cyan_text() { printf "$(style "36")$1$(style "0")"; } 12 | 13 | 14 | progress_bar() { 15 | if [ -z "$1" ] ; then 16 | echo "ERROR: The duration of the progress bar is required" >&2; 17 | exit 1; 18 | fi 19 | 20 | local duration=$1 21 | local increment=$((100/$duration)) 22 | for (( elapsed=0; elapsed<=100; elapsed=elapsed+increment )); do 23 | for ((done=0; done&2; exit 1 8 | } 9 | 10 | has_root_permission() { 11 | [ $(id -u) -eq 0 ] && return $TRUE || return $FALSE 12 | } 13 | 14 | does_user_exit() { 15 | local username="$1" 16 | grep -q "^${username}" /etc/passwd && return $TRUE || return $FALSE 17 | } 18 | 19 | is_valid_file() { 20 | local given_path="$1" 21 | [ -f "$(realpath $given_path)" ] && return $TRUE || return $FALSE 22 | } 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Nishkarsh Raj 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Automation-using-Shell-Scripts 2 | Development Automation using Shell Scripting, Crontab Scheduling, LAMP STACK etc. 3 | 4 | ## How to Contribute 5 | 6 | All contributions welcomed. Follow these [guidelines](CONTRIBUTING.md) to contribute. 7 | 8 | ## License 9 | 10 | This project follows MIT [License](LICENSE) 11 | 12 | 13 | -------------------------------------------------------------------------------- /Shell Scripting Basics/Array Sorting.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | read -p "Enter the array size you want: " size 3 | i=0 4 | declare -a arrayname 5 | while [ $i -lt $size ] 6 | do 7 | read -p "Enter the $(($i+1)) element of array: " arrayname[i] 8 | i=$[$i+1] 9 | done 10 | 11 | max=0 12 | for el in ${arrayname[@]} 13 | do 14 | if [ $el -gt $max ] 15 | then 16 | max=$el 17 | fi 18 | done 19 | 20 | for el in ${arrayname[@]}; 21 | do 22 | case $el in 23 | $max) echo "$el is max" ;; 24 | esac 25 | done 26 | 27 | 28 | -------------------------------------------------------------------------------- /Shell Scripting Basics/Arrays.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | read -p "Enter a variable: " val1 3 | read -p "Enter another variale: " val2 4 | read -p "Enter another variable: " val3 5 | arrayname=($val1 $val2 $val3) 6 | 7 | max=0 8 | for el in ${arrayname[@]} 9 | do 10 | if [ $el -gt $max ] 11 | then 12 | max=$el 13 | fi 14 | done 15 | 16 | for el in ${arrayname[@]}; 17 | do 18 | case $el in 19 | $max) echo "$el is max" ;; 20 | esac 21 | done 22 | 23 | 24 | -------------------------------------------------------------------------------- /Shell Scripting Basics/Basic Script with User Input.sh: -------------------------------------------------------------------------------- 1 | #not including any bash library reference but still will run because executable permissions given and terminal itself is bash. 2 | 3 | # Creating a readonly variable called "Greeting" 4 | readonly greeting="Hello" 5 | 6 | # Creating an ordinary variable called "current_time" 7 | current_time=`date +%X` #above tab tilted apostrophe for working with built in commands 8 | 9 | # Substitute the output of the command "whoami" 10 | echo "Hi, I am $(whoami)." 11 | 12 | # Prompt the user to provide their name 13 | read -e -p "Who are you? " myName 14 | 15 | # Substituting the variables and printing them 16 | echo "${greeting:-Hi}, $myName. Now the time is $current_time" 17 | -------------------------------------------------------------------------------- /Shell Scripting Basics/Calculator with Switch.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | read -p "Enter a number a: " a 3 | read -p "Enter a number b: " b 4 | read -p "Enter 1 to start with addition: " inp 5 | if [ $inp -eq 1 ] 6 | then 7 | case $inp 8 | in 9 | 1) 10 | add=$(($a+$b)) 11 | echo "Addition of input numbers is: ${add}" 12 | ;& 13 | 2) 14 | sub=$(($add-$b)) 15 | echo "Subtraction of Add and B is: ${sub}" 16 | ;& 17 | 3) 18 | mul=$(($sub*$b)) 19 | echo "Multiplication of sub and B is: ${mul}" 20 | ;& 21 | 4) 22 | div=bc <<< "scale = 10; ($mul/$b))" 23 | echo "Division of mul and b is: ${div}" 24 | ;& 25 | 5) 26 | mod=$(($div-($div/$b)*$b)) 27 | echo "Mod of div and b is: ${mod}" 28 | ;& 29 | *) 30 | echo "Wrong choice entered";; 31 | esac 32 | else 33 | echo "Wrong Choice" 34 | fi 35 | -------------------------------------------------------------------------------- /Shell Scripting Basics/Call by reference.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | function greet 3 | { 4 | local -n ref "$1" 5 | echo "Hello $1" 6 | } 7 | read -p "Enter a string: " var 8 | #echo "Call by Value" 9 | #greet $var 10 | echo "Call by reference" 11 | greet $var 12 | 13 | -------------------------------------------------------------------------------- /Shell Scripting Basics/Do While loop.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | count=9 4 | do 5 | while [ $count -gt 0 ] 6 | echo "$count" 7 | count=$[$count-1] 8 | done 9 | -------------------------------------------------------------------------------- /Shell Scripting Basics/Else If.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | number1=5 3 | number2=5 4 | 5 | if [ $number1 -ne $number2 ] 6 | then 7 | if [ $number1 -gt $number2 ] 8 | then 9 | echo "$number1 is greater than $number2" 10 | else 11 | echo "$number2 is greater than $number1" 12 | fi 13 | else 14 | echo "$number1 and $number2 are equal" 15 | fi 16 | -------------------------------------------------------------------------------- /Shell Scripting Basics/For loop.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | names="Name1 Name2 Name3" 3 | for name in $names 4 | do 5 | echo "Hello $name" 6 | done 7 | for number in `seq 1 10` 8 | do 9 | echo "I am $number" 10 | done 11 | 12 | 13 | # seq is sequence for a to b 14 | -------------------------------------------------------------------------------- /Shell Scripting Basics/Function.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | function greet 3 | { 4 | echo "Hello $1" #$1 is the first argument $0 is filename and so all. 5 | } 6 | 7 | greet "Hello Nishkarsh" "Yo" 8 | greet "User" 9 | -------------------------------------------------------------------------------- /Shell Scripting Basics/If Else Basics.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | read -p "Enter a number: " num1 3 | read -p "Enter another number: " num2 4 | 5 | if [ $num1 == $num2 ] 6 | then 7 | echo "Numbers are equal" 8 | else 9 | echo "Numbers are not equal" 10 | fi 11 | -------------------------------------------------------------------------------- /Shell Scripting Basics/If Else.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | number1=5 4 | number2=5 5 | 6 | if [ $number1 -eq $number2 ] 7 | then 8 | echo "$number1 is equal to $number2" 9 | else 10 | echo "$number1 is not equal to $number2" 11 | fi 12 | #-eq double equal compare the integer 13 | #double equal compare 14 | #triple equal compare data type 15 | -------------------------------------------------------------------------------- /Shell Scripting Basics/README.md: -------------------------------------------------------------------------------- 1 | # Automation-using-Shell-Scripts 2 | Development Automation using Shell Scripting. 3 | 4 | Automation is a key principle of DevOps. 5 | Here, Shell Scripts are created to automate the entire workflow stack and schedule the tasks. 6 | -------------------------------------------------------------------------------- /Shell Scripting Basics/RadixSort_Binaryconversion.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | read -p "Enter the array size you want: " size 3 | i=0 4 | declare -a arrayname 5 | while [ $i -lt $size ] 6 | do 7 | read -p "Enter the $(($i+1)) element of array: " arrayname[i] 8 | i=$[$i+1] 9 | done 10 | echo "Input array is: ${arrayname[@]}" 11 | 12 | max=0 13 | for el in ${arrayname[@]} 14 | do 15 | if [ $el -gt $max ] 16 | then 17 | max=$el 18 | fi 19 | done 20 | echo "Max element is found!!!: ${max}" 21 | 22 | declare -a oarr #output array 23 | declare -a carr #count array 24 | #note that -ge is for greater than or equal to and gt is only for greater than 25 | exp=1 26 | z=1 27 | while [ $(($max/$exp)) -gt 0 ] 28 | do 29 | echo "Iteration number ${z} with exp value ${exp}" 30 | 31 | 32 | #echo "Initializing all the elements of count array to 0" 33 | i=0 34 | #assuming d=10 number of digits max 35 | while [ $i -lt 10 ] 36 | do 37 | carr[i]=0 38 | i=$[$i+1] 39 | done 40 | #echo "printing the count array after initialization" 41 | #echo "${carr[@]}" 42 | 43 | i=0 44 | while [ $i -lt $size ] 45 | do 46 | k=$(((${arrayname[i]}/$exp)%10)) 47 | carr[k]=$[${carr[k]}+1] 48 | i=$[$i+1] 49 | done 50 | 51 | i=1 52 | while [ $i -lt 10 ] 53 | do 54 | k=$[$i-1] 55 | carr[i]=$((${carr[i]}+${carr[k]})) 56 | i=$[$i+1] 57 | done 58 | 59 | 60 | i=$[$size-1] 61 | while [ $i -ge 0 ] 62 | do 63 | k=$(((${arrayname[i]}/$exp)%10)) 64 | oarr[$((${carr[k]}-1))]=${arrayname[i]} 65 | carr[k]=$((${carr[k]}-1)) 66 | i=$[$i-1] 67 | done 68 | 69 | echo "Printing the sorted array for current bit iteration" 70 | echo ${oarr[@]} 71 | 72 | z=$[$z+1] 73 | exp=$[$exp*10] 74 | done 75 | 76 | echo "Printing final sorted array" 77 | echo ${oarr[@]} 78 | echo "Radix sort is successfully done!!!" 79 | echo "Converting to the binary form of all the elements of array!!!" 80 | echo "" 81 | 82 | declare -a barrfinal 83 | declare -a barr 84 | j=0 85 | for el in ${oarr[@]} 86 | do 87 | i=0 88 | while [ $el -gt 0 ] 89 | do 90 | barr[i]=$(($el%2)) 91 | barrfinal[j]="${barrfinal[j]} ${barr[i]}" 92 | el=$(($el/2)) 93 | i=$[$i+1] 94 | done 95 | #barrfinal[j]=${barr[@]} 96 | j=$[j+1] 97 | done 98 | 99 | #Barrfinal is stored with reverse binary order... must reverse each element 100 | echo "Printing sorted array with its binary equivalent: " 101 | i=0 102 | while [ $i -lt $size ] 103 | do 104 | echo "${oarr[i]} ==> ${barrfinal[i]}" 105 | i=$[$i+1] 106 | done 107 | 108 | 109 | -------------------------------------------------------------------------------- /Shell Scripting Basics/Standard Input Stream.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Reading the text from stdin and assigning it to the variable named "myName" 4 | read myName 5 | 6 | # Substitute the variable and print the text 7 | echo "Hello ${myName}" 8 | -------------------------------------------------------------------------------- /Shell Scripting Basics/Standard Output and Standard Error Stream.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Send the text to the stdout 3 | echo "Any standard text can be here" 4 | #Send the text to the stderr 5 | echo "Any error text can be here " >&2 6 | 7 | #piping the string to standard error stream 8 | #&0 input stream &1 output stream &2 error stream 9 | -------------------------------------------------------------------------------- /Shell Scripting Basics/Swapping variables using Function.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | function swap 3 | { 4 | eval "$1=${!2} $2=${!1}" # swap two variables without third variable in shell 5 | } 6 | read -p "Enter a number: " num1 7 | read -p "Enter another number: " num2 8 | echo "Before Swapping: " 9 | echo "Number 1 and number 2 are $num1 and $num2 respectively" 10 | swap num1 num2 11 | echo "After swapping: " 12 | echo "Number 1 and number 2 are $num1 and $num2 respectively" 13 | 14 | #Call by reference always in Shell 15 | -------------------------------------------------------------------------------- /Shell Scripting Basics/Switch Basics.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | read -p "Enter a name: " name 3 | case "$name" in 4 | john) echo "Welcome Admin" ;; 5 | *) echo "Access Denied" ;; 6 | alexa) echo "Welcome user" ;; 7 | esac 8 | 9 | 10 | # to continue in case like in c where when we dont specify break... here we use ;& 11 | -------------------------------------------------------------------------------- /Shell Scripting Basics/Switch and Case.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | read -p "Enter your marks: " marks 3 | case $marks 4 | in 5 | 9[0-9]|100) 6 | echo "Your grade is: O" 7 | ;; 8 | 8[0-9]) 9 | echo "Your grade is: A+" 10 | ;; 11 | 7[0-9]) 12 | echo "Your grade is: A" 13 | ;; 14 | 6[0-9]) 15 | echo "Your grade is: B" 16 | ;; 17 | 5[0-9]) 18 | echo "Your grade is: C" 19 | ;; 20 | 4[0-9]) 21 | echo "Your grade is: D" 22 | ;; 23 | *) 24 | echo "Your grade is: F" 25 | ;; 26 | esac 27 | -------------------------------------------------------------------------------- /Shell Scripting Basics/User defined for loop.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | read -p "Enter a string with spaces: " names 3 | for name in $names 4 | do 5 | echo "Hello $name" 6 | done 7 | read -p "Enter a number: " num1 8 | read -p "Enter another number: " num2 9 | for number in `seq $num1 $num2` 10 | do 11 | echo "I am $number" 12 | done 13 | -------------------------------------------------------------------------------- /Shell Scripting Basics/While loop.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | count=9 4 | 5 | while [ $count -gt 0 ] 6 | do 7 | echo "$count" 8 | count=$[$count-1] 9 | done 10 | -------------------------------------------------------------------------------- /Shell Scripting Basics/arraynew.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | declare -a arrayname 3 | arrayname=(10 5 8 4 7) 4 | #sorting 5 | for i in `seq 0 4` 6 | do 7 | for j in `seq 0 $(($j-$i-1))` 8 | do 9 | k=$(($j+1)) 10 | if [ ${arrayname[j]} -lt ${arrayname[k]} ] 11 | then 12 | temp=${arrayname[j]} 13 | arrayname[j]=${arrayname[$((j+1))]} 14 | arrayname[$((j+1))]=${arrayname[j]} 15 | fi 16 | done 17 | done 18 | 19 | 20 | 21 | p=${arrayname[0]} 22 | q=${arrayname[1]} 23 | read -p "Enter 1 to start with addition: " inp 24 | if [ $inp -eq 1 ] 25 | then 26 | case $inp 27 | in 28 | 1) 29 | add=$(($p+$q)) 30 | echo "Addition of input numbers is: ${add}" 31 | ;& 32 | 2) 33 | sub=$(($add-$q)) 34 | echo "Subtraction of Add and B is: ${sub}" 35 | ;& 36 | 3) 37 | mul=$(($sub*$q)) 38 | echo "Multiplication of sub and B is: ${mul}" 39 | ;& 40 | 4) 41 | div=bc <<< "scale = 10; ($mul/$q))" 42 | echo "Division of mul and b is: ${div}" 43 | ;& 44 | 5) 45 | mod=$(($div-($div/$q)*$q)) 46 | echo "Mod of div and b is: ${mod}" 47 | ;& 48 | *) 49 | echo "Wrong choice entered";; 50 | esac 51 | else 52 | echo "Wrong Choice" 53 | fi 54 | 55 | echo "Max value of array is: ${arrayname[4]}" 56 | sum=0 57 | for el in ${arrayname[@]} 58 | do 59 | sum=$(($sum+$el)) 60 | done 61 | five=5 62 | avg=bc <<< "scale =10; ($sum/$five)" 63 | echo "Average is :${avg}" 64 | -------------------------------------------------------------------------------- /Shell Scripting Basics/calbyrefcheck.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | function mul100 3 | { 4 | var=$(($1*100)) 5 | echo "Inside function value of integer is (after function operation): " $var>$1 6 | } 7 | read -p "Enter an integer: " var 8 | mul100 $var 9 | echo "Value of integer after function call is: " $var 10 | -------------------------------------------------------------------------------- /Shell Scripting Basics/commandlineargumentsforscripts.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "Number of arguments are: $#" 3 | echo "Filename is: $0" 4 | i=1 5 | while [ i\<$# ] 6 | do 7 | echo "$i command entered on runtime is: $(($i))" 8 | i=i+1 9 | done 10 | -------------------------------------------------------------------------------- /Shell Scripting Basics/concatenation_script.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "Hello to the Concatenation code!!!" 4 | 5 | #Take first input from user via stdin 6 | read -p "Enter the first string: " str1 7 | 8 | #Take second input from user via stdin 9 | read -p "Enter the second string: " str2 10 | 11 | #Concatenate the string 12 | str="$str1$str2" 13 | 14 | #print the value of str 15 | echo "The concatenated string is: ${str}" 16 | -------------------------------------------------------------------------------- /Shell Scripting Basics/decimaltobinary.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | read -p "Enter a number: " num 4 | declare -a barr 5 | i=0 6 | while [ $num -gt 0 ] 7 | do 8 | barr[i]=$(($num%2)) 9 | num=$(($num/2)) 10 | i=$[$i+1] 11 | done 12 | echo "${barr[@]}" 13 | -------------------------------------------------------------------------------- /Shell Scripting Basics/elif.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | read -p "Enter your name: " 3 | if [ name = "Nishkarsh" ] 4 | then 5 | echo "You are ${myname}" 6 | elif [ name = "Finn Balor" ] 7 | then 8 | echo "You are God!" 9 | else 10 | echo "I don't understand who you are??" 11 | fi 12 | -------------------------------------------------------------------------------- /Shell Scripting Basics/function_basic.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #First program for function in shell scripting 4 | function multiply10 5 | { 6 | n=$(($1*10)) 7 | #echo $n 8 | return $n 9 | } 10 | read -p "Enter a number whom you want to multiply by 10: " num 11 | num1=`multiply10 $num` 12 | echo "Number multiplied by 10 is: $num1" 13 | -------------------------------------------------------------------------------- /Shell Scripting Basics/if_script.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | read -p "Enter your name: " name 3 | if [ $name = "Nishkarsh" ] 4 | then 5 | echo "Access given" 6 | else 7 | echo "Access denied" 8 | fi 9 | 10 | #BCD... if command condition is written inside [] where space must be given from both sides in the condition 11 | #BCD... == is for string comparision, -eq is for integer comparision 12 | #BCD... No space must be given between a variable and its value and equal sign during variable declaration but not during condition 13 | #BCD... Match is case sensitive 14 | -------------------------------------------------------------------------------- /Shell Scripting Basics/input.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #First Input file 3 | echo "Enter your name!!!: " 4 | read myname 5 | #Showing Output 6 | echo "Hello $myname ! Welcome here!!!" 7 | -------------------------------------------------------------------------------- /Shell Scripting Basics/log.tar: -------------------------------------------------------------------------------- 1 | log_adduser.txt0000644000175000017500000000362613342674756013565 0ustar ubuntuubuntuubuntu@ubuntu-VirtualBox:~$ cd .. 2 | ubuntu@ubuntu-VirtualBox:/home$ ls 3 | dev ubuntu 4 | ubuntu@ubuntu-VirtualBox:/home$ deluser dev 5 | /usr/sbin/deluser: Only root may remove a user or group from the system. 6 | ubuntu@ubuntu-VirtualBox:/home$ sudo su 7 | [sudo] password for ubuntu: 8 | root@ubuntu-VirtualBox:/home# deluser dev 9 | /usr/sbin/deluser: The user `dev' does not exist. 10 | root@ubuntu-VirtualBox:/home# cd /home 11 | root@ubuntu-VirtualBox:/home# adduser dev 12 | Adding user `dev' ... 13 | Adding new group `dev' (1001) ... 14 | Adding new user `dev' (1001) with group `dev' ... 15 | The home directory `/home/dev' already exists. Not copying from `/etc/skel'. 16 | Enter new UNIX password: 17 | Retype new UNIX password: 18 | passwd: password updated successfully 19 | Changing the user information for dev 20 | Enter the new value, or press ENTER for the default 21 | Full Name []: Nishkarsh 22 | Room Number []: D-203 23 | Work Phone []: 9005445752 24 | Home Phone []: 25 | Other []: 26 | Is the information correct? [Y/n] Y 27 | root@ubuntu-VirtualBox:/home# sudo usermod -aG sudo dev 28 | root@ubuntu-VirtualBox:/home# chmod 777 dev 29 | root@ubuntu-VirtualBox:/home# cd dev 30 | root@ubuntu-VirtualBox:/home/dev# mkdir nishkarsh 31 | mkdir: cannot create directory ‘nishkarsh’: File exists 32 | root@ubuntu-VirtualBox:/home/dev# mkdir nish 33 | root@ubuntu-VirtualBox:/home/dev# cd nish 34 | root@ubuntu-VirtualBox:/home/dev/nish# touch nish.txt 35 | root@ubuntu-VirtualBox:/home/dev/nish# echo "My name is Nishkarsh Raj Khare" >> nish.txt 36 | root@ubuntu-VirtualBox:/home/dev/nish# cat nish.txt 37 | My name is Nishkarsh Raj Khare 38 | root@ubuntu-VirtualBox:/home/dev/nish# addgroup ops 39 | Adding group `ops' (GID 1002) ... 40 | Done. 41 | root@ubuntu-VirtualBox:/home/dev/nish# sudo usermod -a -G ops dev 42 | root@ubuntu-VirtualBox:/home/dev/nish# grep ops /etc/groups 43 | grep: /etc/groups: No such file or directory 44 | root@ubuntu-VirtualBox:/home/dev/nish# grep ops /etc/group 45 | whoopsie:x:117: 46 | ops:x:1002:dev 47 | root@ubuntu-VirtualBox:/home/dev/nish# exit 48 | exit 49 | ubuntu@ubuntu-VirtualBox:/home$ 50 | 51 | -------------------------------------------------------------------------------- /Shell Scripting Basics/log.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Basics/log.tar.gz -------------------------------------------------------------------------------- /Shell Scripting Basics/log_adduser.txt: -------------------------------------------------------------------------------- 1 | ubuntu@ubuntu-VirtualBox:~$ cd .. 2 | ubuntu@ubuntu-VirtualBox:/home$ ls 3 | dev ubuntu 4 | ubuntu@ubuntu-VirtualBox:/home$ deluser dev 5 | /usr/sbin/deluser: Only root may remove a user or group from the system. 6 | ubuntu@ubuntu-VirtualBox:/home$ sudo su 7 | [sudo] password for ubuntu: 8 | root@ubuntu-VirtualBox:/home# deluser dev 9 | /usr/sbin/deluser: The user `dev' does not exist. 10 | root@ubuntu-VirtualBox:/home# cd /home 11 | root@ubuntu-VirtualBox:/home# adduser dev 12 | Adding user `dev' ... 13 | Adding new group `dev' (1001) ... 14 | Adding new user `dev' (1001) with group `dev' ... 15 | The home directory `/home/dev' already exists. Not copying from `/etc/skel'. 16 | Enter new UNIX password: 17 | Retype new UNIX password: 18 | passwd: password updated successfully 19 | Changing the user information for dev 20 | Enter the new value, or press ENTER for the default 21 | Full Name []: Nishkarsh 22 | Room Number []: D-203 23 | Work Phone []: 9005445752 24 | Home Phone []: 25 | Other []: 26 | Is the information correct? [Y/n] Y 27 | root@ubuntu-VirtualBox:/home# sudo usermod -aG sudo dev 28 | root@ubuntu-VirtualBox:/home# chmod 777 dev 29 | root@ubuntu-VirtualBox:/home# cd dev 30 | root@ubuntu-VirtualBox:/home/dev# mkdir nishkarsh 31 | mkdir: cannot create directory ‘nishkarsh’: File exists 32 | root@ubuntu-VirtualBox:/home/dev# mkdir nish 33 | root@ubuntu-VirtualBox:/home/dev# cd nish 34 | root@ubuntu-VirtualBox:/home/dev/nish# touch nish.txt 35 | root@ubuntu-VirtualBox:/home/dev/nish# echo "My name is Nishkarsh Raj Khare" >> nish.txt 36 | root@ubuntu-VirtualBox:/home/dev/nish# cat nish.txt 37 | My name is Nishkarsh Raj Khare 38 | root@ubuntu-VirtualBox:/home/dev/nish# addgroup ops 39 | Adding group `ops' (GID 1002) ... 40 | Done. 41 | root@ubuntu-VirtualBox:/home/dev/nish# sudo usermod -a -G ops dev 42 | root@ubuntu-VirtualBox:/home/dev/nish# grep ops /etc/groups 43 | grep: /etc/groups: No such file or directory 44 | root@ubuntu-VirtualBox:/home/dev/nish# grep ops /etc/group 45 | whoopsie:x:117: 46 | ops:x:1002:dev 47 | root@ubuntu-VirtualBox:/home/dev/nish# exit 48 | exit 49 | ubuntu@ubuntu-VirtualBox:/home$ 50 | 51 | -------------------------------------------------------------------------------- /Shell Scripting Basics/log_basiccommands.txt: -------------------------------------------------------------------------------- 1 | ubuntu@ubuntu-VirtualBox:~/Desktop/DevOps_Automation_Lab$ hostname 2 | ubuntu-VirtualBox 3 | ubuntu@ubuntu-VirtualBox:~/Desktop/DevOps_Automation_Lab$ hostname -I 4 | 10.0.2.15 5 | ubuntu@ubuntu-VirtualBox:~/Desktop/DevOps_Automation_Lab$ clear 6 | ubuntu@ubuntu-VirtualBox:~/Desktop/DevOps_Automation_Lab$ cat log_adduser.txt | head -10 | tail -10 7 | ubuntu@ubuntu-VirtualBox:~$ cd .. 8 | ubuntu@ubuntu-VirtualBox:/home$ ls 9 | dev ubuntu 10 | ubuntu@ubuntu-VirtualBox:/home$ deluser dev 11 | /usr/sbin/deluser: Only root may remove a user or group from the system. 12 | ubuntu@ubuntu-VirtualBox:/home$ sudo su 13 | [sudo] password for ubuntu: 14 | root@ubuntu-VirtualBox:/home# deluser dev 15 | /usr/sbin/deluser: The user `dev' does not exist. 16 | root@ubuntu-VirtualBox:/home# cd /home 17 | ubuntu@ubuntu-VirtualBox:~/Desktop/DevOps_Automation_Lab$ ls -t 18 | log.tar.gz log.tar log_adduser.txt variable.sh output.sh input.sh 19 | ubuntu@ubuntu-VirtualBox:~/Desktop/DevOps_Automation_Lab$ ls -l -S 20 | total 32 21 | -rw-r--r-- 1 ubuntu ubuntu 10240 Sep 2 11:23 log.tar 22 | -rw-r--r-- 1 ubuntu ubuntu 1942 Sep 2 11:19 log_adduser.txt 23 | -rw-r--r-- 1 ubuntu ubuntu 822 Sep 2 11:37 log.tar.gz 24 | -rwxr-xr-x 1 ubuntu ubuntu 152 Aug 21 07:28 output.sh 25 | -rwxr-xr-x 1 ubuntu ubuntu 125 Aug 21 07:25 input.sh 26 | -rwxr-xr-x 1 ubuntu ubuntu 70 Aug 21 07:58 variable.sh 27 | ubuntu@ubuntu-VirtualBox:~/Desktop/DevOps_Automation_Lab$ hostname 28 | ubuntu-VirtualBox 29 | ubuntu@ubuntu-VirtualBox:~/Desktop/DevOps_Automation_Lab$ hostname -I 30 | 10.0.2.15 31 | ubuntu@ubuntu-VirtualBox:~/Desktop/DevOps_Automation_Lab$ pwd 32 | /home/ubuntu/Desktop/DevOps_Automation_Lab 33 | ubuntu@ubuntu-VirtualBox:~/Desktop/DevOps_Automation_Lab$ sudo bash 34 | [sudo] password for ubuntu: 35 | root@ubuntu-VirtualBox:~/Desktop/DevOps_Automation_Lab# exit 36 | exit 37 | ubuntu@ubuntu-VirtualBox:~/Desktop/DevOps_Automation_Lab$ df 38 | Filesystem 1K-blocks Used Available Use% Mounted on 39 | udev 991184 0 991184 0% /dev 40 | tmpfs 204132 1540 202592 1% /run 41 | /dev/sda1 20509264 8052352 11392056 42% / 42 | tmpfs 1020656 0 1020656 0% /dev/shm 43 | tmpfs 5120 4 5116 1% /run/lock 44 | tmpfs 1020656 0 1020656 0% /sys/fs/cgroup 45 | /dev/loop1 1664 1664 0 100% /snap/gnome-calculator/154 46 | /dev/loop2 3456 3456 0 100% /snap/gnome-system-monitor/36 47 | /dev/loop3 21504 21504 0 100% /snap/gnome-logs/25 48 | /dev/loop4 14848 14848 0 100% /snap/gnome-logs/37 49 | /dev/loop6 3840 3840 0 100% /snap/gnome-system-monitor/51 50 | /dev/loop5 13312 13312 0 100% /snap/gnome-characters/103 51 | /dev/loop7 3840 3840 0 100% /snap/gnome-system-monitor/54 52 | /dev/loop8 89088 89088 0 100% /snap/core/4917 53 | /dev/loop9 35584 35584 0 100% /snap/gtk-common-themes/319 54 | /dev/loop11 13312 13312 0 100% /snap/gnome-characters/117 55 | /dev/loop10 12544 12544 0 100% /snap/gnome-characters/69 56 | /dev/loop13 143488 143488 0 100% /snap/gnome-3-26-1604/59 57 | /dev/loop12 14848 14848 0 100% /snap/gnome-logs/40 58 | /dev/loop14 144384 144384 0 100% /snap/gnome-3-26-1604/70 59 | /dev/loop16 2432 2432 0 100% /snap/gnome-calculator/199 60 | /dev/loop15 89088 89088 0 100% /snap/core/5145 61 | tmpfs 204128 28 204100 1% /run/user/120 62 | /dev/loop17 90112 90112 0 100% /snap/core/5328 63 | tmpfs 204128 28 204100 1% /run/user/1000 64 | ubuntu@ubuntu-VirtualBox:~/Desktop/DevOps_Automation_Lab$ du Desktop 65 | du: cannot access 'Desktop': No such file or directory 66 | ubuntu@ubuntu-VirtualBox:~/Desktop/DevOps_Automation_Lab$ ]cd .. 67 | cd 68 | Command ']cd' not found, did you mean: 69 | 70 | command 'hcd' from deb hfsutils 71 | command 'mcd' from deb mtools 72 | command 'bcd' from deb bsdgames 73 | 74 | Try: sudo apt install 75 | 76 | ubuntu@ubuntu-VirtualBox:~/Desktop/DevOps_Automation_Lab$ cdcd 77 | 78 | Command 'cdcd' not found, but can be installed with: 79 | 80 | sudo apt install cdcd 81 | 82 | ubuntu@ubuntu-VirtualBox:~/Desktop/DevOps_Automation_Lab$ cd 83 | ubuntu@ubuntu-VirtualBox:~$ du Desktop/ 84 | 36 Desktop/DevOps_Automation_Lab 85 | 40 Desktop/ 86 | ubuntu@ubuntu-VirtualBox:~$ df -m 87 | Filesystem 1M-blocks Used Available Use% Mounted on 88 | udev 968 0 968 0% /dev 89 | tmpfs 200 2 198 1% /run 90 | /dev/sda1 20029 7864 11126 42% / 91 | tmpfs 997 0 997 0% /dev/shm 92 | tmpfs 5 1 5 1% /run/lock 93 | tmpfs 997 0 997 0% /sys/fs/cgroup 94 | /dev/loop1 2 2 0 100% /snap/gnome-calculator/154 95 | /dev/loop2 4 4 0 100% /snap/gnome-system-monitor/36 96 | /dev/loop3 21 21 0 100% /snap/gnome-logs/25 97 | /dev/loop4 15 15 0 100% /snap/gnome-logs/37 98 | /dev/loop6 4 4 0 100% /snap/gnome-system-monitor/51 99 | /dev/loop5 13 13 0 100% /snap/gnome-characters/103 100 | /dev/loop7 4 4 0 100% /snap/gnome-system-monitor/54 101 | /dev/loop8 87 87 0 100% /snap/core/4917 102 | /dev/loop9 35 35 0 100% /snap/gtk-common-themes/319 103 | /dev/loop11 13 13 0 100% /snap/gnome-characters/117 104 | /dev/loop10 13 13 0 100% /snap/gnome-characters/69 105 | /dev/loop13 141 141 0 100% /snap/gnome-3-26-1604/59 106 | /dev/loop12 15 15 0 100% /snap/gnome-logs/40 107 | /dev/loop14 141 141 0 100% /snap/gnome-3-26-1604/70 108 | /dev/loop16 3 3 0 100% /snap/gnome-calculator/199 109 | /dev/loop15 87 87 0 100% /snap/core/5145 110 | tmpfs 200 1 200 1% /run/user/120 111 | /dev/loop17 88 88 0 100% /snap/core/5328 112 | tmpfs 200 1 200 1% /run/user/1000 113 | ubuntu@ubuntu-VirtualBox:~$ ls -lah 114 | total 83M 115 | drwxr-xr-x 16 ubuntu ubuntu 4.0K Sep 2 11:05 . 116 | drwxr-xr-x 4 root root 4.0K Aug 16 19:45 .. 117 | -rw-r--r-- 1 root root 83M Jul 14 02:53 atom-amd64.deb 118 | -rw------- 1 ubuntu ubuntu 1.2K Sep 2 11:48 .bash_history 119 | -rw-r--r-- 1 ubuntu ubuntu 220 Jul 19 10:58 .bash_logout 120 | -rw-r--r-- 1 ubuntu ubuntu 3.7K Jul 19 10:58 .bashrc 121 | drwx------ 14 ubuntu ubuntu 4.0K Aug 21 07:42 .cache 122 | drwx------ 13 ubuntu ubuntu 4.0K Aug 21 07:25 .config 123 | drwxr-xr-x 3 ubuntu ubuntu 4.0K Sep 2 11:24 Desktop 124 | drwxr-xr-x 2 ubuntu ubuntu 4.0K Jul 19 11:08 Documents 125 | drwxr-xr-x 2 ubuntu ubuntu 4.0K Jul 19 11:08 Downloads 126 | -rw-r--r-- 1 ubuntu ubuntu 8.8K Jul 19 10:58 examples.desktop 127 | drwx------ 2 ubuntu ubuntu 4.0K Jul 19 11:45 .gconf 128 | drwx------ 3 ubuntu ubuntu 4.0K Jul 19 11:08 .gnupg 129 | -rw------- 1 ubuntu ubuntu 2.9K Sep 2 11:05 .ICEauthority 130 | drwx------ 3 ubuntu ubuntu 4.0K Jul 19 11:08 .local 131 | drwx------ 5 ubuntu ubuntu 4.0K Aug 6 11:30 .mozilla 132 | drwxr-xr-x 2 ubuntu ubuntu 4.0K Jul 19 11:08 Music 133 | drwxr-xr-x 2 ubuntu ubuntu 4.0K Sep 2 11:47 Pictures 134 | -rw-r--r-- 1 ubuntu ubuntu 807 Jul 19 10:58 .profile 135 | drwxr-xr-x 2 ubuntu ubuntu 4.0K Jul 19 11:08 Public 136 | -rw-r--r-- 1 ubuntu ubuntu 0 Jul 19 11:09 .sudo_as_admin_successful 137 | drwxr-xr-x 2 ubuntu ubuntu 4.0K Jul 19 11:08 Templates 138 | drwxr-xr-x 2 ubuntu ubuntu 4.0K Jul 19 11:08 Videos 139 | -rw------- 1 ubuntu ubuntu 1.1K Sep 2 10:56 .viminfo 140 | ubuntu@ubuntu-VirtualBox:~$ ^C 141 | ubuntu@ubuntu-VirtualBox:~$ cd Desktop/DevOps_Automation_Lab/ 142 | ubuntu@ubuntu-VirtualBox:~/Desktop/DevOps_Automation_Lab$ gedit log_basiccommands.txt 143 | 144 | -------------------------------------------------------------------------------- /Shell Scripting Basics/output.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Output goes from two streams 3 | 4 | #Stdout stream 5 | echo "This is the Stdout stream!!!!" 6 | #Stderr stream 7 | echo "This is the Stderr stream!!!!" >&2 8 | 9 | -------------------------------------------------------------------------------- /Shell Scripting Basics/read.txt: -------------------------------------------------------------------------------- 1 | 1) Input using read 2 | 2) Error and Output stream 3 | 3) readonly using date and tilde 4 | 4) case using marks 5 | 5) if compare 6 | 6) if compare with user input 7 | 7) nested if 8 | 8) nested if with user input 9 | 9) nested if -lt 10 | 10) nested if -lt with user input 11 | 11) case basic 12 | 12) for loop 13 | 13) for loop using user 14 | 14) function 15 | 15) calling 16 | 16) call by reference 17 | 17) else if 18 | 18) while 19 | 19) do loop 20 | 20) array 21 | 22 | 23 | 24 | doubt!!! 25 | 3 26 | -------------------------------------------------------------------------------- /Shell Scripting Basics/variable.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | myname="Nishkarsh" 3 | echo "My name is $myname Raj Khare!!!" 4 | -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Automated_Backup/backup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #tar = Tape Archive tool for compression 4 | tar -cvf /backupfolder/backup.tar /home/nishkarshraj/Desktop/Automation-using-Shell-Scripts 5 | 6 | #Go to the backup folder location 7 | cd /backupfolder 8 | 9 | #Show the size of the folder 10 | du -sh 11 | 12 | -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Automated_Backup/date_backup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Compress the folder with foldername + date and take backup 4 | filename="backup_`date +%d`_`date +%m`_`date +%Y`.tar"; 5 | 6 | # Create compressed file using tar and move to backup folder 7 | tar cvf /backupfolder/$filename /home/nishkarshraj/Desktop/HelloWorld 8 | 9 | # Move to Backup folder 10 | cd /backupfolder 11 | 12 | # List the content 13 | ls 14 | 15 | # List the disk usage 16 | du -sh 17 | -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Automated_Backup/img/1.Createbackupfolder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Automated_Backup/img/1.Createbackupfolder.png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Automated_Backup/img/2.CreateShellScript.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Automated_Backup/img/2.CreateShellScript.png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Automated_Backup/img/3.ShellScript.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Automated_Backup/img/3.ShellScript.png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Automated_Backup/img/4.Execute.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Automated_Backup/img/4.Execute.png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Automated_Backup/img/5.Output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Automated_Backup/img/5.Output.png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Automated_Backup/img/6.SettingCrontab.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Automated_Backup/img/6.SettingCrontab.png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Automated_Backup/img/7.crontab.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Automated_Backup/img/7.crontab.png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Automated_Backup/img/Remove (1).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Automated_Backup/img/Remove (1).png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Automated_Backup/img/Remove (2).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Automated_Backup/img/Remove (2).png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Automated_Backup/img/date (1).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Automated_Backup/img/date (1).png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Automated_Backup/img/date (2).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Automated_Backup/img/date (2).png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Automated_Backup/img/multiple (1).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Automated_Backup/img/multiple (1).png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Automated_Backup/img/multiple (2).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Automated_Backup/img/multiple (2).png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Automated_Backup/multiplebackup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #Specify folders whose backup is to be taken in variables 4 | f1="/home/nishkarshraj/Desktop/Automation-using-Shell-Scripts" 5 | f2="/home/nishkarshraj/Desktop/Computer-Graphics" 6 | f3="/home/nishkarshraj/Desktop/HelloWorld" 7 | 8 | #tar = Tape Archive tool for compression 9 | #Creating same backup tar file for all specified folders 10 | tar -cvf /backupfolder/backup.tar $f1 $f2 $f3 11 | 12 | #Go to the backup folder location 13 | cd /backupfolder 14 | 15 | #Show the size of the folder 16 | du -sh 17 | 18 | -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Automated_Backup/remove_backup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | find "/backupfolder" -type f -mtime +5 -exec rm {} \; 4 | -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Basics/img/Arithmetic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Basics/img/Arithmetic.png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Basics/img/Command Line Arguments.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Basics/img/Command Line Arguments.png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Basics/img/HelloWorld.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Basics/img/HelloWorld.png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Basics/img/Read.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Basics/img/Read.png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Basics/img/Special.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Basics/img/Special.png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Basics/img/Standard Inout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Basics/img/Standard Inout.png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Basics/img/Unset.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Basics/img/Unset.png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Basics/img/Variable.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Basics/img/Variable.png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Basics/src/HelloWorld.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "Hello World" 3 | -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Basics/src/arithmetic.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "Arithmetic Operations on Shell"; 3 | read -p "Enter an Real value: " val1 4 | read -p "Enter another Real value: " val2 5 | echo "Addition: $(($val1+$val2))" 6 | echo "Subtraction: $(($val1-$val2))" 7 | echo "Multiplication: $(($val1*$val2))" 8 | div=$(($val1/$val2)) 9 | echo "Division: ${div}" 10 | -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Basics/src/commandlineargument.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "Command Line Arguments" 3 | echo "File name: $0"; 4 | echo "First Argument: $1"; 5 | echo "Second Argument: $2"; 6 | echo "Number of Arguments sent: $#"; 7 | echo "All arguments in same quotes: $*"; 8 | echo "All arguments in individual quotes: $@"; 9 | -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Basics/src/deletevar.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | var1="Variable to be deleted!"; 3 | echo "$var1"; 4 | unset var1; 5 | echo "Printing unset variable: $var1"; 6 | # Trying unset keyword on readonly 7 | readonly var2="Readonly var"; 8 | echo $var2; 9 | unset var2; 10 | echo $var2; 11 | -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Basics/src/inout.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "Hello $(whoami)! I am your assistant!" 3 | read -p "Enter your real name: " name 4 | echo "Hello $name" 5 | -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Basics/src/readvar.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # This is how you add comments 3 | # Reading variable without promptings users 4 | read var1 5 | echo "$var1" 6 | # Reading variable by prompting user 7 | read -p "Enter a value: " var2 8 | echo "$var2" 9 | # Reading a silent variable by prompting user 10 | read -sp "Enter a value: " var3 11 | echo "" # By default it has an endline attached 12 | echo "$var3" 13 | -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Basics/src/specialvar.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "Current File Name: $0" 3 | echo "Process number of current Shell: $$" 4 | echo "Process Number of last background command: $!" 5 | echo "Exit ID of last executed command: $?" 6 | -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Basics/src/variable.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # creating a normal variable 3 | var1="Variable 1"; # No spacing between variable name and value else error 4 | echo $var1; 5 | # Changing value of variable 1 6 | var1="Variable 1 updated"; 7 | echo $var1; 8 | # Creating readonly variable 9 | readonly var2="Readonly var"; 10 | echo $var2; 11 | var2="Can I change?"; 12 | echo $var2; 13 | -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Control Structures/img/case (1).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Control Structures/img/case (1).png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Control Structures/img/case (2).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Control Structures/img/case (2).png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Control Structures/img/elif (1).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Control Structures/img/elif (1).png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Control Structures/img/elif (2).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Control Structures/img/elif (2).png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Control Structures/img/if (1).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Control Structures/img/if (1).png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Control Structures/img/if (2).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Control Structures/img/if (2).png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Control Structures/src/if_elif_else.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "Enter two numbers" 3 | read num1 4 | read num2 5 | if [ $num1 -gt $num2 ] 6 | then 7 | echo "$num1 is greater than $num2" 8 | elif [ $num1 -eq $num2 ] 9 | then 10 | echo "Both numbers are equal" 11 | else 12 | echo "$num2 is greater than $num1" 13 | fi 14 | -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Control Structures/src/if_else.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | read -p "Enter username: " name 3 | if [ $name == "admin" ] 4 | then 5 | echo "Access Granted" 6 | else 7 | echo "Access Denied" 8 | fi 9 | -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Control Structures/src/switch_case.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | read -p "Enter your name: " name 3 | case $name in 4 | admin) echo "Access Granted! Welcome Admin" ;; 5 | root) echo "Access Granted! Welcome root" ;; 6 | *) echo "Access Denied" ;; 7 | esac 8 | -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Crontab Scheduler/README.md: -------------------------------------------------------------------------------- 1 | # Crontab Scheduler Blog 2 | 3 | Check out my blog published by OpenGenus [here](https://iq.opengenus.org/p/a74916c8-143f-445f-91cf-073d4af49e5a/) -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Crontab Scheduler/img/e.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Crontab Scheduler/img/e.png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Crontab Scheduler/img/etc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Crontab Scheduler/img/etc.png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Crontab Scheduler/img/etcron.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Crontab Scheduler/img/etcron.png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Crontab Scheduler/img/extensions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Crontab Scheduler/img/extensions.png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Crontab Scheduler/img/l.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Crontab Scheduler/img/l.png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Crontab Scheduler/img/r.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Crontab Scheduler/img/r.png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Crontab Scheduler/img/u.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Crontab Scheduler/img/u.png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Crontab Scheduler/img/var.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Crontab Scheduler/img/var.png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Crontab Scheduler/img/varcron.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Crontab Scheduler/img/varcron.png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Functions/img/Scope (1).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Functions/img/Scope (1).png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Functions/img/Scope (2).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Functions/img/Scope (2).png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Functions/img/funct (1).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Functions/img/funct (1).png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Functions/img/funct (2).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Functions/img/funct (2).png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Functions/img/multicall3 (1).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Functions/img/multicall3 (1).png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Functions/img/multicall3 (2).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Functions/img/multicall3 (2).png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Functions/img/multiple (1).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Functions/img/multiple (1).png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Functions/img/multiple (2).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Functions/img/multiple (2).png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Functions/img/nested (1).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Functions/img/nested (1).png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Functions/img/nested (2).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Functions/img/nested (2).png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Functions/img/parameter (1).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Functions/img/parameter (1).png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Functions/img/parameter (2).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Functions/img/parameter (2).png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Functions/img/return (1).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Functions/img/return (1).png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Functions/img/return (2).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Functions/img/return (2).png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Functions/img/return1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Functions/img/return1.png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Functions/img/return2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Functions/img/return2.png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Functions/src/func_parameters.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | function1() 3 | { 4 | echo "Parameter 0 (File Name): $0" 5 | echo "Parameter 1: $1" 6 | echo "Parameter 2: $2" 7 | } 8 | function1 p1 p2; 9 | -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Functions/src/function.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Create function 3 | function1() 4 | { 5 | echo "Inside Function body"; 6 | } 7 | # Invoke Function using function name 8 | function1 9 | 10 | -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Functions/src/multicall.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | add() 4 | { 5 | return $(($1+$2)) 6 | } 7 | multiply() 8 | { 9 | return $(($1*$2)) 10 | } 11 | # Call Addition for 3 and 4 == 7 12 | add 3 4 13 | echo "$?" 14 | 15 | # Call multiplication for 3 and 4 == 12 16 | multiply 3 4 17 | echo "$?" 18 | 19 | # Call Addition for 5 and 4 == 9 20 | add 5 4 21 | echo "$?" 22 | 23 | -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Functions/src/multiplefunctioncall.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | add() 3 | { 4 | return $(($1+$2)) 5 | } 6 | multiply() 7 | { 8 | return $(($1*$2)) 9 | } 10 | # Call Addition for 3 and 4 == 7 11 | add 3 4 12 | # Call multiplication for 3 and 4 == 12 13 | multiply 3 4 14 | # Call Addition for 5 and 4 == 9 15 | add 5 4 16 | # Store answer (always stores final function call returned value) 17 | ans=$? 18 | echo "$ans" 19 | 20 | -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Functions/src/nestedfunction.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "Nested functions" 3 | 4 | # First function 5 | function1() 6 | { 7 | echo "Function 1 body" 8 | function2; 9 | } 10 | 11 | # Second function 12 | function2() 13 | { 14 | echo "Function 2 body" 15 | } 16 | 17 | function1 18 | 19 | -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Functions/src/return_code.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | function1() 3 | { 4 | return $(($1*$2)) 5 | } 6 | echo "Multiplication in Shell using Functions" 7 | echo "Enter two numbers" 8 | read num1 9 | read num2 10 | function1 $num1 $num2 11 | mul=$? 12 | echo "Multiplied value is $mul" 13 | -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Functions/src/scope.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Declaring a global variable 3 | gvar="I am the global variable!!!" 4 | 5 | # Define a function 6 | function1() 7 | { 8 | # Declaring a local variable 9 | lvar="I am the local variable" 10 | echo "$gvar" 11 | echo "$lvar" 12 | } 13 | 14 | # Call the function 15 | function1 16 | -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Looping in Shell Scripts/For loop/for_break.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | i=1; #initialize variable to 1 3 | for (( ; ; )) #infinite loop 4 | do 5 | echo "$i" 6 | i=$(($i+1)) 7 | if [ $i -eq 10 ] 8 | then 9 | break; 10 | fi 11 | done 12 | -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Looping in Shell Scripts/For loop/for_continue.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | for i in 1 2 3 4 5 3 | do 4 | if [ $i -eq 3 ] 5 | then 6 | continue; 7 | fi; 8 | echo "$i"; 9 | done 10 | -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Looping in Shell Scripts/For loop/for_ctype.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | for (( i=0; i<10; i++ )) 3 | do 4 | echo "$i"; 5 | done 6 | -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Looping in Shell Scripts/For loop/for_increment.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | for i in {1..10} 3 | do 4 | echo "This is $i increment" 5 | done 6 | -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Looping in Shell Scripts/For loop/for_infinite.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | for (( ; ; )) 3 | do 4 | echo "Infinite loop"; 5 | done 6 | -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Looping in Shell Scripts/For loop/for_items.sh: -------------------------------------------------------------------------------- 1 | for i in Hello World "Hello World" Bye 2 | do 3 | echo "$i" 4 | done 5 | -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Looping in Shell Scripts/For loop/for_jump.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | for i in {1..10..2} 3 | do 4 | echo "This is $i"; 5 | done 6 | -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Looping in Shell Scripts/For loop/for_seq.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | for i in `seq 1 10` 3 | do 4 | echo "This is $i increment" 5 | done 6 | -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Looping in Shell Scripts/For loop/forloop_tuple.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | for i in 1 2 3 4 5 6 7 8 3 | do 4 | echo "This is loop $i"; 5 | done 6 | -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Looping in Shell Scripts/While loop/while_basics.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | i=1 3 | while [ $i -le 5 ] 4 | do 5 | echo "$i"; 6 | i=$(($i+1)); 7 | done 8 | -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Looping in Shell Scripts/While loop/while_infinite.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | while : 3 | do 4 | echo "infinite loop"; 5 | done 6 | -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Looping in Shell Scripts/img/For Loop/For Break.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Looping in Shell Scripts/img/For Loop/For Break.png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Looping in Shell Scripts/img/For Loop/For continue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Looping in Shell Scripts/img/For Loop/For continue.png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Looping in Shell Scripts/img/For Loop/ForTuple.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Looping in Shell Scripts/img/For Loop/ForTuple.png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Looping in Shell Scripts/img/For Loop/General For.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Looping in Shell Scripts/img/For Loop/General For.png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Looping in Shell Scripts/img/For Loop/Incrementfor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Looping in Shell Scripts/img/For Loop/Incrementfor.png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Looping in Shell Scripts/img/For Loop/ctype for.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Looping in Shell Scripts/img/For Loop/ctype for.png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Looping in Shell Scripts/img/For Loop/for Infinite 1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Looping in Shell Scripts/img/For Loop/for Infinite 1.png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Looping in Shell Scripts/img/For Loop/for Infinite 2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Looping in Shell Scripts/img/For Loop/for Infinite 2.png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Looping in Shell Scripts/img/For Loop/forJump.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Looping in Shell Scripts/img/For Loop/forJump.png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Looping in Shell Scripts/img/For Loop/forseq.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Looping in Shell Scripts/img/For Loop/forseq.png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Looping in Shell Scripts/img/While loop/While basics.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Looping in Shell Scripts/img/While loop/While basics.png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Looping in Shell Scripts/img/While loop/infinite 1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Looping in Shell Scripts/img/While loop/infinite 1.png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/Looping in Shell Scripts/img/While loop/infinite 2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/Looping in Shell Scripts/img/While loop/infinite 2.png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/tar_compression_tool/README.md: -------------------------------------------------------------------------------- 1 | [Link to Blog](https://iq.opengenus.org/p/d909afac-8f3a-4784-9755-b892f565cd32/) 2 | -------------------------------------------------------------------------------- /Shell Scripting Tutorial/tar_compression_tool/img/Multiple.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/tar_compression_tool/img/Multiple.png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/tar_compression_tool/img/append.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/tar_compression_tool/img/append.png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/tar_compression_tool/img/compare.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/tar_compression_tool/img/compare.png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/tar_compression_tool/img/cvf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/tar_compression_tool/img/cvf.png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/tar_compression_tool/img/diff_create.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/tar_compression_tool/img/diff_create.png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/tar_compression_tool/img/diff_delete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/tar_compression_tool/img/diff_delete.png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/tar_compression_tool/img/diff_modify.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/tar_compression_tool/img/diff_modify.png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/tar_compression_tool/img/diff_newfile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/tar_compression_tool/img/diff_newfile.png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/tar_compression_tool/img/gz.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/tar_compression_tool/img/gz.png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/tar_compression_tool/img/list.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/tar_compression_tool/img/list.png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/tar_compression_tool/img/shell.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/tar_compression_tool/img/shell.png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/tar_compression_tool/img/update.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/tar_compression_tool/img/update.png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/tar_compression_tool/img/xgz.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/tar_compression_tool/img/xgz.png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/tar_compression_tool/img/xvf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NishkarshRaj/Automation-using-Shell-Scripts/d7c728a64c09fe14435db81f5ece29982b5744af/Shell Scripting Tutorial/tar_compression_tool/img/xvf.png -------------------------------------------------------------------------------- /Shell Scripting Tutorial/tar_compression_tool/tar.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Simple compression 4 | tar cvf file1.tar /home/nishkarshraj/Desktop/HelloWorld 5 | du -sh file1.tar 6 | 7 | # GNU compression 8 | tar cvzf file2.tar.gz /home/nishkarshraj/Desktop/HelloWorld 9 | du -sh file2.tar.gz 10 | 11 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-cayman --------------------------------------------------------------------------------