├── Chapter01 ├── script1.txt ├── script10.txt ├── script13.txt ├── script15.txt ├── script16.txt ├── script17.txt ├── script19.txt ├── script2.txt ├── script21.txt ├── script22.txt ├── script23.txt ├── script3.txt ├── script4.txt ├── script5.txt ├── script6.txt ├── script7.txt ├── script8.txt └── script9.txt ├── Chapter02 ├── backup.sh ├── script10.txt ├── script11.txt ├── script13.txt ├── script14.txt └── script15.txt ├── Chapter03 ├── remove_duplicates.txt ├── script16.txt └── script5.txt ├── Chapter04 ├── script1.txt ├── script2.txt └── script3.txt ├── Chapter05 ├── img_downloader.sh ├── script11.txt ├── script2.txt ├── script4.txt ├── script7.txt └── script8.txt ├── Chapter07 └── script1.txt ├── Chapter08 ├── pingTest.txt ├── script2.txt └── script3.txt ├── Chapter09 ├── intruder_detect.sh ├── pcpu.sh ├── script3.txt └── script4.txt ├── Chapter10 ├── script1.txt ├── script3.txt ├── script5.txt ├── script6.txt ├── script7.txt ├── script8.txt └── script9.txt ├── LICENSE └── README.md /Chapter01/script1.txt: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #Filename: printf.sh 4 | 5 | 6 | printf "%-5s %-10s %-4s\n" No Name Mark 7 | 8 | 9 | printf "%-5s %-10s %-4.2f\n" 1 Sarath 80.3456 10 | 11 | 12 | printf "%-5s %-10s %-4.2f\n" 2 James 90.9989 13 | 14 | printf "%-5s %-10s %-4.2f\n" 3 Jeff 77.564 15 | -------------------------------------------------------------------------------- /Chapter01/script10.txt: -------------------------------------------------------------------------------- 1 | fname() 2 | 3 | { 4 | 5 | 6 | echo $1, $2; #Accessing arg1 and arg2 7 | 8 | 9 | echo "$@"; # Printing all arguments as list at once 10 | 11 | 12 | echo "$*"; # Similar to $@, but arguments taken as single entity 13 | 14 | 15 | return 0; # Return value 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Chapter01/script13.txt: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #Filename: success_test.sh 4 | 5 | 6 | # Evaluate the arguments on the command line - ie success_test.sh 'ls | grep txt' 7 | 8 | 9 | eval $@ 10 | 11 | 12 | if [ $? -eq 0 ]; 13 | 14 | 15 | then 16 | 17 | 18 | echo "$CMD executed successfully" 19 | 20 | 21 | else 22 | 23 | 24 | echo "$CMD terminated unsuccessfully" 25 | 26 | 27 | fi 28 | -------------------------------------------------------------------------------- /Chapter01/script15.txt: -------------------------------------------------------------------------------- 1 | repeat() 2 | 3 | { 4 | 5 | while true 6 | 7 | 8 | do 9 | 10 | 11 | $@ && return 12 | 13 | 14 | done 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Chapter01/script16.txt: -------------------------------------------------------------------------------- 1 | data="name,gender 2 | ,rollno,location" 3 | 4 | # To read each of the item in a variable, we can use IFS. 5 | 6 | 7 | oldIFS=$IFS 8 | 9 | 10 | IFS=, # IFS is now a , 11 | 12 | 13 | for item in $data; 14 | 15 | 16 | do 17 | 18 | 19 | echo Item: $item 20 | 21 | 22 | done 23 | 24 | IFS=$oldIFS 25 | -------------------------------------------------------------------------------- /Chapter01/script17.txt: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #Desc: Illustration of IFS 4 | 5 | 6 | line="root:x:0:0:root:/root:/bin/bash" 7 | 8 | 9 | oldIFS=$IFS; 10 | 11 | 12 | IFS=":" 13 | 14 | 15 | count=0 16 | 17 | 18 | for item in $line; 19 | 20 | 21 | do 22 | 23 | 24 | [ $count -eq 0 ] && user=$item; 25 | 26 | 27 | [ $count -eq 6 ] && shell=$item; 28 | 29 | 30 | let count++ 31 | 32 | 33 | done; 34 | 35 | 36 | IFS=$oldIFS 37 | 38 | echo $user\'s shell is $shell; 39 | -------------------------------------------------------------------------------- /Chapter01/script19.txt: -------------------------------------------------------------------------------- 1 | x=0; 2 | 3 | until [ $x -eq 9 ]; # [ $x -eq 9 ] is the condition 4 | 5 | 6 | do 7 | 8 | 9 | let x++; echo $x; 10 | 11 | done 12 | -------------------------------------------------------------------------------- /Chapter01/script2.txt: -------------------------------------------------------------------------------- 1 | $ env 2 | PWD=/home/clif/ShellCookBook 3 | 4 | HOME=/home/clif 5 | 6 | SHELL=/bin/bash 7 | # -- And many more lines 8 | -------------------------------------------------------------------------------- /Chapter01/script21.txt: -------------------------------------------------------------------------------- 1 | fpath="/etc/passwd" 2 | 3 | if [ -e $fpath ]; then 4 | 5 | 6 | echo File exists; 7 | 8 | 9 | else 10 | 11 | 12 | echo Does not exist; 13 | 14 | fi 15 | -------------------------------------------------------------------------------- /Chapter01/script22.txt: -------------------------------------------------------------------------------- 1 | str1="Not empty " 2 | 3 | str2="" 4 | 5 | 6 | if [[ -n $str1 ]] && [[ -z $str2 ]]; 7 | 8 | 9 | then 10 | 11 | 12 | echo str1 is nonempty and str2 is empty string. 13 | 14 | fi 15 | -------------------------------------------------------------------------------- /Chapter01/script23.txt: -------------------------------------------------------------------------------- 1 | # Define my colors for ls 2 | 3 | LS_COLORS='no=00:di=01;46:ln=00;36:pi=40;33:so=00;35:bd=40;33;01' 4 | 5 | export LS_COLORS 6 | 7 | # My primary prompt 8 | 9 | PS1='Hello $USER'; export PS1 10 | 11 | # Applications I install outside the normal distro paths 12 | 13 | PATH=$PATH:/opt/MySpecialApplication/bin; export PATH 14 | 15 | # Shorthand for commands I use frequently 16 | 17 | function lc 18 | () { /bin/ls -C $* ; } 19 | -------------------------------------------------------------------------------- /Chapter01/script3.txt: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #Filename :variables.sh 4 | 5 | 6 | fruit=apple 7 | 8 | 9 | count=5 10 | echo "We have $count ${fruit}(s)" 11 | -------------------------------------------------------------------------------- /Chapter01/script4.txt: -------------------------------------------------------------------------------- 1 | if [ $UID -ne 0 ]; then 2 | 3 | echo Non root user. Please run as root. 4 | 5 | 6 | else 7 | 8 | 9 | echo Root user 10 | 11 | fi 12 | -------------------------------------------------------------------------------- /Chapter01/script5.txt: -------------------------------------------------------------------------------- 1 | if test $UID -ne 0 2 | 3 | then 4 | 5 | 6 | echo Non root user. Please run as root 7 | 8 | 9 | else 10 | 11 | 12 | echo Root User 13 | 14 | fi 15 | -------------------------------------------------------------------------------- /Chapter01/script6.txt: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #Filename: sleep.sh 4 | 5 | 6 | echo Count: 7 | 8 | 9 | tput sc 10 | 11 | 12 | 13 | 14 | # Loop for 40 seconds 15 | 16 | 17 | for count in `seq 0 40` 18 | 19 | 20 | do 21 | 22 | 23 | tput rc 24 | 25 | 26 | tput ed 27 | 28 | 29 | echo -n $count 30 | 31 | 32 | sleep 1 33 | 34 | 35 | done 36 | -------------------------------------------------------------------------------- /Chapter01/script7.txt: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #Filename: debug.sh 4 | 5 | 6 | for i in {1..6}; 7 | 8 | 9 | do 10 | 11 | 12 | set -x 13 | 14 | 15 | echo $i 16 | 17 | 18 | set +x 19 | 20 | 21 | done 22 | 23 | echo "Script executed" 24 | -------------------------------------------------------------------------------- /Chapter01/script8.txt: -------------------------------------------------------------------------------- 1 | construct to iterate from a start to end value, instead of the 2 | seq 3 | command used in the previous example. 4 | This construct is slightly faster than invoking the 5 | seq 6 | command. 7 | 19.      8 | The aforementioned debugging methods 9 | are provided by Bash built-ins. They produce debugging information in a fixed format. 10 | In many cases, we need debugging information in our own format. We can define a _DEBUG environment variable to enable and disable debugging and generate messages 11 | in our own debugging style. 12 | -------------------------------------------------------------------------------- /Chapter01/script9.txt: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function DEBUG() 4 | 5 | 6 | { 7 | 8 | 9 | [ "$_DEBUG" == "on" ] && $@ || : 10 | 11 | 12 | } 13 | 14 | 15 | for i in {1..10} 16 | 17 | 18 | do 19 | 20 | 21 | DEBUG echo "I is $i" 22 | 23 | done 24 | -------------------------------------------------------------------------------- /Chapter02/backup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # backup.sh 3 | # Backup files with suffix. Do not backup temp files that start with ~ 4 | read -p " What folder should be backed up:" folder 5 | read -p " What type of files should be backed up: " suffix 6 | find $folder -name "*.$suffix" -a ! -name '~*' \ 7 | -exec cp {} $BACKUP/$LOGNAME/$folder 8 | echo "Backed up files from $folder to $BACKUP/$LOGNAME/$folder" 9 | -------------------------------------------------------------------------------- /Chapter02/script10.txt: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #Filename: checkword.sh 4 | 5 | word=$1 6 | 7 | grep "^$1$" /usr/share/dict/british-english -q 8 | 9 | if [ $? -eq 0 ]; then 10 | 11 | echo $word is a dictionary word; 12 | 13 | else 14 | 15 | echo $word is not a dictionary word; 16 | 17 | fi 18 | -------------------------------------------------------------------------------- /Chapter02/script11.txt: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #Filename: aspellcheck.sh 4 | 5 | word=$1 6 | 7 | output=`echo \"$word\" | aspell list` 8 | 9 | if [ -z $output ]; then 10 | 11 | echo $word is a dictionary word; 12 | 13 | else 14 | 15 | echo $word is not a dictionary word; 16 | 17 | fi 18 | -------------------------------------------------------------------------------- /Chapter02/script13.txt: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # backup.sh 4 | 5 | # Backup files with suffix. 6 | Do not backup temp files that start with ~ 7 | read -p " What folder should be backed up:" folder 8 | 9 | read -p " What type of files should be backed up: " suffix 10 | 11 | find $folder -name "*.$suffix" -a ! -name '~*' \ 12 | -exec cp {} \ 13 | $BACKUP/$LOGNAME/$folder 14 | 15 | echo "Backed up files from $folder to $BACKUP/$LOGNAME/$folder" 16 | -------------------------------------------------------------------------------- /Chapter02/script14.txt: -------------------------------------------------------------------------------- 1 | #Filename: automate_expect.tcl 2 | 3 | spawn ./backup.sh 4 | 5 | expect { 6 | 7 | "*folder*" { 8 | 9 | send "notes\n" 10 | 11 | exp_continue 12 | 13 | } 14 | 15 | "*type*" { 16 | 17 | send "docx\n" 18 | 19 | exp_continue 20 | 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /Chapter02/script15.txt: -------------------------------------------------------------------------------- 1 | #/bin/bash 2 | 3 | #filename: generate_checksums.sh 4 | 5 | PIDARRAY=() 6 | 7 | for file in File1.iso File2.iso 8 | 9 | do 10 | 11 | md5sum $file & 12 | 13 | PIDARRAY+=("$!") 14 | 15 | done 16 | 17 | wait ${PIDARRAY[@]} 18 | -------------------------------------------------------------------------------- /Chapter03/remove_duplicates.txt: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #Filename: remove_duplicates.sh 4 | 5 | #Description: Find and remove duplicate files and 6 | 7 | # keep one sample of each file. 8 | 9 | ls -lS --time-style=long-iso | awk 'BEGIN { 10 | 11 | getline; getline; 12 | 13 | name1=$8; size=$5 14 | 15 | } 16 | 17 | { 18 | 19 | name2=$8; 20 | 21 | if (size==$5) 22 | 23 | { 24 | 25 | "md5sum "name1 | getline; csum1=$1; 26 | 27 | "md5sum "name2 | getline; csum2=$1; 28 | 29 | if ( csum1==csum2 ) 30 | 31 | { 32 | 33 | print name1; print name2 34 | 35 | } 36 | 37 | }; 38 | 39 | size=$5; name1=name2; 40 | 41 | }' | sort -u > duplicate_files 42 | 43 | 44 | cat duplicate_files | xargs -I {} md5sum {} | \ 45 | 46 | sort | uniq -w 32 | awk '{ print $2 }' | \ 47 | 48 | sort -u > unique_files 49 | 50 | echo Removing.. 51 | 52 | comm duplicate_files unique_files -3 | tee /dev/stderr | \ 53 | xargs rm 54 | 55 | echo Removed duplicates files successfully. 56 | 57 | -------------------------------------------------------------------------------- /Chapter03/script16.txt: -------------------------------------------------------------------------------- 1 | $> cat makePan.sh 2 | 3 | # Invoke as: sh makePan.sh OriginalImage.jpg prefix width height xoffset yoffset 4 | 5 | # Clean out any old data 6 | 7 | rm -f tmpFiles 8 | 9 | # Create 200 still images, stepping through the original xoffset and yoffset 10 | 11 | # pixels at a time 12 | 13 | for o in `seq 1 200` 14 | 15 | do 16 | 17 | x=$[ $o+$5 ] 18 | 19 | convert -extract $3x$4+$x+$6 $1 $2_$x.jpg 20 | echo $2_$x.jpg 21 | >> tmpFiles 22 | done 23 | 24 | #Stitch together the image files into a mpg video file 25 | 26 | mencoder mf://@tmpFiles -mf fps=30 -ovc lavc -lavcopts \ 27 | 28 | vcodec=msmpeg4v2 -noskip -o $2.mpg 29 | -------------------------------------------------------------------------------- /Chapter03/script5.txt: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Filename: filestat.sh 4 | 5 | if [ $# -ne 1 ]; 6 | 7 | then 8 | 9 | echo "Usage is $0 basepath"; 10 | 11 | exit 12 | 13 | fi 14 | 15 | path=$1 16 | 17 | declare -A statarray; 18 | 19 | while read line; 20 | 21 | do 22 | 23 | ftype=`file -b "$line" | cut -d, -f1` 24 | 25 | let statarray["$ftype"]++; 26 | 27 | done < <(find $path -type f -print) 28 | 29 | echo ============ File types and counts ============= 30 | 31 | for ftype in "${!statarray[@]}"; 32 | 33 | do 34 | 35 | echo $ftype : ${statarray["$ftype"]} 36 | 37 | done 38 | 39 | 40 | 18.     41 | 42 | -------------------------------------------------------------------------------- /Chapter04/script1.txt: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #Filename: silent_grep.sh 4 | 5 | #Desc: Testing whether a file contain a text or not 6 | 7 | if [ $# -ne 2 ]; then 8 | 9 | echo "Usage: $0 match_text filename" 10 | 11 | exit 1 12 | 13 | fi 14 | 15 | 16 | 17 | match_text=$1 18 | filename=$2 19 | 20 | grep -q "$match_text" $filename 21 | 22 | 23 | if [ $? -eq 0 ]; then 24 | 25 | echo "The text exists in the file" 26 | 27 | else 28 | 29 | echo "Text does not exist in the file" 30 | 31 | fi 32 | -------------------------------------------------------------------------------- /Chapter04/script2.txt: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #Name: word_freq.sh 4 | 5 | #Desc: Find out frequency of words in a file 6 | 7 | if [ $# -ne 1 ]; 8 | 9 | then 10 | 11 | echo "Usage: $0 filename"; 12 | 13 | exit -1 14 | 15 | fi 16 | 17 | filename=$1 18 | 19 | egrep -o "\b[[:alpha:]]+\b" $filename | \ 20 | 21 | awk '{ count[$0]++ } 22 | 23 | END{ printf("%-14s%s\n","Word","Count") ; 24 | 25 | for(ind in count) 26 | 27 | { printf("%-14s%d\n",ind,count[ind]); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Chapter04/script3.txt: -------------------------------------------------------------------------------- 1 | egrep -o "\b[[:alpha:]]+\b" $filename | tr [A=Z] [a-z] | \ 2 | 3 | awk '{ count[$0]++ } 4 | 5 | END{ printf("%-14s%s\n","Word","Count") ; 6 | 7 | for(ind in count) 8 | 9 | { printf("%-14s%d\n",ind,count[ind]); 10 | } 11 | }' | sort 12 | 13 | -------------------------------------------------------------------------------- /Chapter05/img_downloader.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Filename: img_downloader.sh 3 | 4 | if [ $# -ne 3 ]; 5 | then 6 | echo "Usage: $0 URL -d DIRECTORY" 7 | exit -1 8 | fi 9 | 10 | while [ $# -gt 0 ] 11 | do 12 | case $1 in 13 | -d) shift; directory=$1; shift;; 14 | *) url=$1; shift;; 15 | esac 16 | done 17 | 18 | echo "URL: $url" 19 | echo "DIR: $directory" 20 | 21 | mkdir -p $directory; 22 | baseurl=$(echo $url | egrep -o "https?://[a-z.\-]+") 23 | echo Downloading $url 24 | curl -s $url | egrep -o "]*>" | 25 | sed 's/ /tmp/$$.list 27 | cd $directory; 28 | while read filename; 29 | do 30 | echo Downloading $filename 31 | curl -s -O "$filename" --silent 32 | done < /tmp/$$.list 33 | -------------------------------------------------------------------------------- /Chapter05/script11.txt: -------------------------------------------------------------------------------- 1 |
2 | 3 | 15 | 16 | 17 |
18 | -------------------------------------------------------------------------------- /Chapter05/script2.txt: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | username='PUT_USERNAME_HERE' 5 | 6 | password='PUT_PASSWORD_HERE' 7 | 8 | 9 | 10 | SHOW_COUNT=5 # No of recent unread mails to be shown 11 | 12 | 13 | echo 14 | 15 | 16 | curl -u $username:$password --silent \ 17 | "https://mail.google.com/mail/feed/atom" | \ >file 18 | 19 | 20 | curl -u $username:$password --silent \ 21 | "https://mail.google.com/mail/feed/atom" | \ 22 | 23 | tr -d '\n' | sed 's::\n:g' |\ 24 | 25 | sed -n 's/.*\(.*\)<\/title.*<author><name>\([^<]*\)<\/name><email> 26 | \([^<]*\).*/From: \2 [\3] \nSubject: \1\n/p' | \ 27 | 28 | head -n $(( $SHOW_COUNT * 3 )) 29 | -------------------------------------------------------------------------------- /Chapter05/script4.txt: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #Filename: generate_album.sh 4 | 5 | 6 | #Description: Create a photo album using images in current directory 7 | 8 | echo "Creating album.." 9 | 10 | mkdir -p thumbs 11 | 12 | 13 | cat <<EOF1 > index.html 14 | 15 | 16 | <html> 17 | 18 | 19 | <head> 20 | 21 | 22 | <style> 23 | 24 | 25 | body 26 | 27 | { 28 | 29 | 30 | width:470px; 31 | 32 | 33 | margin:auto; 34 | 35 | 36 | border: 1px dashed grey; 37 | 38 | 39 | padding:10px; 40 | 41 | 42 | } 43 | 44 | img 45 | 46 | { 47 | 48 | 49 | margin:5px; 50 | 51 | 52 | border: 1px solid black; 53 | 54 | } 55 | 56 | </style> 57 | 58 | 59 | </head> 60 | 61 | 62 | <body> 63 | 64 | 65 | <center><h1> #Album title </h1></center> 66 | 67 | 68 | <p> 69 | 70 | 71 | EOF1 72 | 73 | 74 | for img in *.jpg; 75 | 76 | do 77 | 78 | 79 | convert "$img" -resize "100x" "thumbs/$img" 80 | 81 | 82 | echo "<a href=\"$img\" > 83 | " >>index.html 84 | 85 | echo " 86 | <img src=\"thumbs/$img\" title=\"$img\" /></a>" >> index.html 87 | 88 | 89 | done 90 | 91 | cat <<EOF2 >> index.html 92 | 93 | </p> 94 | 95 | </body> 96 | 97 | </html> 98 | 99 | 100 | EOF2 101 | 102 | 103 | echo Album generated to index.html 104 | -------------------------------------------------------------------------------- /Chapter05/script7.txt: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | #Desc: A script to fetch definitions from dictionaryapi.com 5 | 6 | 7 | apikey=YOUR_API_KEY_HERE 8 | 9 | 10 | if [ $# -ne 2 ]; 11 | 12 | 13 | then 14 | 15 | 16 | echo -e "Usage: $0 WORD NUMBER" 17 | 18 | 19 | exit -1; 20 | 21 | 22 | fi 23 | 24 | 25 | curl --silent \ 26 | http://www.dictionaryapi.com/api/v1/references/learners/xml/$1?key=$apikey | \ 27 | 28 | grep -o \<dt\>.*\</dt\> | \ 29 | 30 | sed 's$</*[a-z]*>$$g' | \ 31 | 32 | head -n $2 | nl 33 | -------------------------------------------------------------------------------- /Chapter05/script8.txt: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | #Desc: Script to track changes to webpage 5 | 6 | 7 | if [ $# -ne 1 ]; 8 | 9 | 10 | then 11 | 12 | 13 | echo -e "$Usage: $0 URL\n" 14 | 15 | 16 | exit 1; 17 | 18 | 19 | fi 20 | 21 | 22 | first_time=0 23 | 24 | 25 | # Not first time 26 | 27 | 28 | if [ ! -e "last.html" ]; 29 | 30 | 31 | then 32 | 33 | 34 | first_time=1 35 | 36 | 37 | # Set it is first time run 38 | 39 | 40 | fi 41 | 42 | 43 | curl --silent $1 -o recent.html 44 | 45 | 46 | if [ $first_time -ne 1 ]; 47 | 48 | 49 | then 50 | 51 | 52 | changes=$(diff -u last.html recent.html) 53 | 54 | 55 | if [ -n "$changes" ]; 56 | 57 | 58 | then 59 | 60 | 61 | echo -e "Changes:\n" 62 | 63 | 64 | echo "$changes" 65 | 66 | 67 | else 68 | 69 | 70 | echo -e "\nWebsite has no changes" 71 | 72 | 73 | fi 74 | 75 | 76 | else 77 | 78 | 79 | echo "[First run] Archiving.." 80 | 81 | 82 | fi 83 | 84 | 85 | cp recent.html last.html 86 | -------------------------------------------------------------------------------- /Chapter07/script1.txt: -------------------------------------------------------------------------------- 1 | FILE_LIST="file1 file2 file3 file4 file5" 2 | 3 | 4 | for f in $FILE_LIST; 5 | 6 | 7 | do 8 | 9 | 10 | tar -rvf archive.tar $f 11 | 12 | 13 | done 14 | 15 | 16 | gzip archive.tar 17 | -------------------------------------------------------------------------------- /Chapter08/pingTest.txt: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | # Change base address 192.168.0 according to your network. 5 | 6 | 7 | for ip in 192.168.0.{1..255} ; 8 | 9 | 10 | do 11 | 12 | 13 | ( 14 | 15 | 16 | ping $ip -c2 &> /dev/null ; 17 | 18 | 19 | if [ $? -eq 0 ]; 20 | 21 | 22 | then 23 | 24 | 25 | echo $ip is alive 26 | 27 | 28 | fi 29 | 30 | 31 | )& 32 | 33 | 34 | done 35 | 36 | 37 | wait 38 | -------------------------------------------------------------------------------- /Chapter08/script2.txt: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #Filename: ftp.sh 4 | 5 | #Automated FTP transfer 6 | 7 | HOST='example.com' 8 | 9 | USER='foo' 10 | 11 | PASSWD='password' 12 | 13 | lftp -i -n -u ${USER}:${PASSWD} $HOST <<EOF 14 | 15 | user ${USER} ${PASSWD} 16 | 17 | binary 18 | 19 | cd /home/foo 20 | 21 | put testfile.jpg 22 | 23 | 24 | quit 25 | 26 | EOF 27 | -------------------------------------------------------------------------------- /Chapter08/script3.txt: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | #Description: Connect to Wireless LAN 5 | 6 | 7 | #Modify the parameters below according to your settings 8 | 9 | 10 | ######### PARAMETERS ########### 11 | 12 | 13 | IFACE=wlan0 14 | 15 | 16 | IP_ADDR=192.168.1.5 17 | 18 | 19 | SUBNET_MASK=255.255.255.0 20 | 21 | 22 | GW=192.168.1.1 23 | 24 | 25 | HW_ADDR='00:1c:bf:87:25:d2' 26 | 27 | 28 | #Comment above line if you don't want to spoof mac address 29 | 30 | 31 | ESSID="homenet" 32 | 33 | 34 | WEP_KEY=8b140b20e7 35 | 36 | 37 | FREQ=2.462G 38 | 39 | 40 | ################################# 41 | 42 | 43 | KEY_PART="" 44 | 45 | 46 | if [[ -n $WEP_KEY ]]; 47 | 48 | 49 | then 50 | 51 | 52 | KEY_PART="key $WEP_KEY" 53 | 54 | 55 | fi 56 | 57 | 58 | if [ $UID -ne 0 ]; 59 | 60 | 61 | then 62 | 63 | 64 | echo "Run as root" 65 | 66 | 67 | exit 1; 68 | 69 | 70 | fi 71 | 72 | 73 | # Shut down the interface before setting new config 74 | 75 | 76 | /sbin/ifconfig $IFACE down 77 | 78 | 79 | if [[ -n $HW_ADDR ]]; 80 | 81 | 82 | then 83 | 84 | 85 | /sbin/ifconfig $IFACE hw ether $HW_ADDR 86 | 87 | 88 | echo Spoofed MAC ADDRESS to $HW_ADDR 89 | 90 | 91 | fi 92 | 93 | 94 | /sbin/iwconfig $IFACE essid $ESSID $KEY_PART freq $FREQ 95 | 96 | 97 | /sbin/ifconfig $IFACE $IP_ADDR netmask $SUBNET_MASK 98 | 99 | 100 | route add default gw $GW $IFACE 101 | 102 | 103 | echo Successfully configured $IFACE 104 | -------------------------------------------------------------------------------- /Chapter09/intruder_detect.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Filename: intruder_detect.sh 3 | #Description: Intruder reporting tool with auth.log input 4 | AUTHLOG=/var/log/auth.log 5 | 6 | if [[ -n $1 ]]; 7 | then 8 | AUTHLOG=$1 9 | echo Using Log file : $AUTHLOG 10 | fi 11 | 12 | # Collect the failed login attempts 13 | LOG=/tmp/failed.$$.log 14 | grep "Failed pass" $AUTHLOG > $LOG 15 | 16 | # extract the users who failed 17 | users=$(cat $LOG | awk '{ print $(NF-5) }' | sort | uniq) 18 | 19 | # extract the IP Addresses of failed attempts 20 | ip_list="$(egrep -o "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+" $LOG | sort | uniq)" 21 | 22 | 23 | printf "%-10s|%-3s|%-16s|%-33s|%s\n" "User" "Attempts" "IP address"\ "Host" "Time range" 24 | 25 | # Loop through IPs and Users who failed. 26 | 27 | for ip in $ip_list; 28 | do 29 | for user in $users; 30 | do 31 | # Count attempts by this user from this IP 32 | 33 | attempts=`grep $ip $LOG | grep " $user " | wc -l` 34 | 35 | if [ $attempts -ne 0 ] 36 | then 37 | first_time=`grep $ip $LOG | grep " $user " | head -1 | cut -c-16` 38 | time="$first_time" 39 | if [ $attempts -gt 1 ] 40 | then 41 | last_time=`grep $ip $LOG | grep " $user " | tail -1 | cut -c-16` 42 | time="$first_time -> $last_time" 43 | fi 44 | HOST=$(host $ip 8.8.8.8 | tail -1 | awk '{ print $NF }' ) 45 | printf "%-10s|%-3s|%-16s|%-33s|%-s\n" "$user" "$attempts" "$ip"\ "$HOST" "$time"; 46 | fi 47 | done 48 | done 49 | 50 | rm $LOG 51 | -------------------------------------------------------------------------------- /Chapter09/pcpu.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Name: pcpu_usage.sh 3 | #Description: Script to calculate cpu usage by processes for 1 hour 4 | 5 | #Change the SECS to total seconds to monitor CPU usage. 6 | #UNIT_TIME is the interval in seconds between each sampling 7 | 8 | SECS=3600 9 | UNIT_TIME=60 10 | 11 | STEPS=$(( $SECS / $UNIT_TIME )) 12 | 13 | echo Watching CPU usage... ; 14 | 15 | # Collect data in temp file 16 | 17 | for((i=0;i<STEPS;i++)) 18 | do 19 | ps -eocomm,pcpu | egrep -v '(0.0)|(%CPU)' >> /tmp/cpu_usage.$$ 20 | sleep $UNIT_TIME 21 | done 22 | 23 | # Process collected data 24 | echo 25 | echo CPU eaters : 26 | 27 | cat /tmp/cpu_usage.$$ | \ 28 | awk ' 29 | { process[$1]+=$2; } 30 | END{ 31 | for(i in process) 32 | { 33 | printf("%-20s %s\n",i, process[i]) ; 34 | } 35 | 36 | }' | sort -nrk 2 | head 37 | 38 | #Remove the temporary log file 39 | rm /tmp/cpu_usage.$$ 40 | -------------------------------------------------------------------------------- /Chapter09/script3.txt: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | #Description: Monitor disk usage health for remote systems 5 | 6 | 7 | logfile="diskusage.log" 8 | 9 | 10 | if [[ -n $1 ]] 11 | 12 | 13 | then 14 | 15 | 16 | logfile=$1 17 | 18 | 19 | fi 20 | 21 | 22 | # Use the environment variable or modify this to a hardcoded value 23 | 24 | 25 | user=$USER 26 | 27 | 28 | #provide the list of remote machine IP addresses 29 | 30 | 31 | IP_LIST="127.0.0.1 0.0.0.0" 32 | 33 | IP_LIST="192.168.1.2" 34 | 35 | 36 | # Or collect them at runtime with nmap 37 | 38 | 39 | # IP_LIST=`nmap -sn 192.168.1.2-255 | grep scan | grep cut -c22-` 40 | 41 | 42 | if [ ! -e $logfile ] 43 | 44 | 45 | then 46 | 47 | 48 | printf "%-8s %-14s %-9s %-8s %-6s %-6s %-6s %s\n" \ 49 | "Date" "IP address" "Device" "Capacity" "Used" "Free" \ 50 | "Percent" "Status" > $logfile 51 | 52 | 53 | fi 54 | 55 | 56 | ( 57 | 58 | 59 | for ip in $IP_LIST; 60 | 61 | 62 | do 63 | 64 | 65 | ssh $user@$ip 'df -H' | grep ^/dev/ > /tmp/$$.df 66 | 67 | 68 | while read line; 69 | 70 | 71 | do 72 | 73 | 74 | cur_date=$(date +%D) 75 | 76 | 77 | printf "%-8s %-14s " $cur_date $ip 78 | 79 | 80 | echo $line | \ 81 | awk '{ printf("%-9s %-8s %-6s %-6s %-8s"122919461 ,$1,$2,$3,$4,$5); }' 82 | 83 | 84 | pusg=$(echo $line | egrep -o "[0-9]+%") 85 | 86 | 87 | pusg=${pusg/\%/}; 88 | 89 | 90 | if [ $pusg -lt 80 ]; 91 | 92 | 93 | then 94 | 95 | 96 | echo SAFE 97 | 98 | 99 | else 100 | 101 | 102 | echo ALERT 103 | 104 | 105 | fi 106 | 107 | 108 | done< /tmp/$$.df 109 | 110 | 111 | 112 | done 113 | 114 | 115 | ) >> $logfile 116 | -------------------------------------------------------------------------------- /Chapter09/script4.txt: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #Filename: active_users.sh 4 | 5 | 6 | 7 | #Description: Reporting tool to find out active users 8 | 9 | log=/var/log/wtmp 10 | 11 | if [[ -n $1 ]]; 12 | 13 | then 14 | 15 | 16 | 17 | log=$1 18 | 19 | 20 | 21 | fi 22 | 23 | printf "%-4s %-10s %-10s %-6s %-8s\n" "Rank" "User" "Start" \ 24 | 25 | "Logins" "Usage hours" 26 | 27 | last -f $log | head -n -2 > /tmp/ulog.$$ 28 | 29 | cat /tmp/ulog.$$ | cut -d' ' -f1 | 30 | sort | 31 | uniq> /tmp/users.$$ 32 | 33 | ( 34 | 35 | while read user; 36 | 37 | 38 | 39 | do 40 | 41 | 42 | 43 | grep ^$user /tmp/ulog.$$ > /tmp/user.$$ 44 | 45 | 46 | 47 | minutes=0 48 | 49 | while read t 50 | 51 | do 52 | 53 | 54 | 55 | s=$(echo $t | awk -F: '{ print ($1 * 60) + $2 }') 56 | 57 | 58 | 59 | let minutes=minutes+s 60 | 61 | 62 | 63 | done< <(cat /tmp/user.$$ | awk '{ print $NF }' | tr -d ')(') 64 | 65 | firstlog=$(tail -n 1 /tmp/user.$$ | awk '{ print $5,$6 }') 66 | 67 | nlogins=$(cat /tmp/user.$$ | wc -l) 68 | 69 | hours=$(echo "$minutes / 60.0" | bc) 70 | 71 | printf "%-10s %-10s %-6s %-8s\n" $user "$firstlog" $nlogins $hours 72 | 73 | done< /tmp/users.$$ 74 | 75 | ) | 76 | sort -nrk 4 | awk '{ printf("%-4s %s\n", NR, $0) }' 77 | 78 | rm /tmp/users.$$ /tmp/user.$$ /tmp/ulog.$$ 79 | -------------------------------------------------------------------------------- /Chapter10/script1.txt: -------------------------------------------------------------------------------- 1 | #/bin/bash 2 | 3 | 4 | #Description: Signal handler 5 | 6 | 7 | function handler() 8 | 9 | 10 | { 11 | 12 | 13 | echo Hey, received signal : SIGINT 14 | 15 | 16 | } 17 | 18 | 19 | # $$ is a special variable that returns process ID of current 20 | 21 | 22 | # process/script 23 | 24 | 25 | echo My process ID is $$ 26 | 27 | 28 | #handler is the name of the signal handler function for SIGINT signal 29 | 30 | 31 | trap 'handler' SIGINT 32 | 33 | 34 | while true; 35 | 36 | 37 | do 38 | 39 | 40 | sleep 1 41 | 42 | 43 | done 44 | -------------------------------------------------------------------------------- /Chapter10/script3.txt: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | case $1 in 5 | 6 | 7 | init ) 8 | 9 | 10 | cmd="CREATE TABLE address \ 11 | 12 | 13 | (name string, phone string, email string);" ;; 14 | query ) 15 | 16 | 17 | cmd="SELECT name, phone, email FROM address \ 18 | 19 | 20 | WHERE $2 LIKE '$3';";;insert ) 21 | 22 | 23 | cmd="INSERT INTO address (name, phone, email) \ 24 | 25 | 26 | VALUES ( '$2', '$3', '$4' );";; 27 | 28 | esac 29 | 30 | 31 | # Send the command to sqlite3 and reformat the output 32 | 33 | 34 | echo $cmd | sqlite3 $HOME/addr.db | sed 's/|/\n/g' 35 | 36 | -------------------------------------------------------------------------------- /Chapter10/script5.txt: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | #Description: Create MySQL database and table 5 | 6 | 7 | USER="user" 8 | 9 | 10 | PASS="user" 11 | 12 | 13 | mysql -u $USER -p$PASS <<EOF 2> /dev/null 14 | 15 | 16 | CREATE DATABASE students; 17 | 18 | 19 | EOF 20 | 21 | 22 | [ $? -eq 0 ] && echo Created DB || echo DB already exist 23 | 24 | 25 | mysql -u $USER -p$PASS students <<EOF 2> /dev/null 26 | 27 | 28 | CREATE TABLE students( 29 | 30 | 31 | id int, 32 | 33 | 34 | name varchar(100), 35 | 36 | 37 | mark int, 38 | 39 | 40 | dept varchar(4) 41 | 42 | 43 | ); 44 | 45 | 46 | EOF 47 | 48 | 49 | [ $? -eq 0 ] && echo Created table students || echo Table students already exist 50 | 51 | 52 | mysql -u $USER -p$PASS students <<EOF 53 | 54 | 55 | DELETE FROM students; 56 | 57 | 58 | EOF 59 | -------------------------------------------------------------------------------- /Chapter10/script6.txt: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | #Description: Read from CSV and write to MySQLdb 5 | 6 | 7 | USER="user" 8 | 9 | 10 | PASS="user" 11 | 12 | 13 | if [ $# -ne 1 ]; 14 | 15 | 16 | then 17 | 18 | 19 | echo $0 DATAFILE 20 | 21 | 22 | echo 23 | 24 | 25 | exit 2 26 | 27 | 28 | fi 29 | 30 | 31 | data=$1 32 | 33 | 34 | while read line; 35 | 36 | 37 | do 38 | 39 | 40 | oldIFS=$IFS 41 | 42 | 43 | IFS=, 44 | 45 | 46 | values=($line) 47 | 48 | 49 | values[1]="\"`echo ${values[1]} | tr ' ' '#' `\"" 50 | 51 | 52 | values[3]="\"`echo ${values[3]}`\"" 53 | 54 | 55 | query=`echo ${values[@]} | tr ' #' ', ' ` 56 | 57 | 58 | IFS=$oldIFS 59 | 60 | 61 | mysql -u $USER -p$PASS students <<EOF 62 | 63 | 64 | INSERT INTO students VALUES($query); 65 | 66 | 67 | EOF 68 | 69 | 70 | done< $data 71 | 72 | 73 | echo Wrote data into DB 74 | -------------------------------------------------------------------------------- /Chapter10/script7.txt: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | #Description: Read from the database 5 | 6 | 7 | USER="user" 8 | 9 | 10 | PASS="user" 11 | 12 | 13 | depts=`mysql -u $USER -p$PASS students <<EOF | tail -n +2 14 | 15 | 16 | SELECT DISTINCT dept FROM students; 17 | 18 | 19 | EOF` 20 | 21 | 22 | for d in $depts; 23 | 24 | 25 | do 26 | 27 | 28 | echo Department : $d 29 | 30 | 31 | result="`mysql -u $USER -p$PASS students <<EOF 32 | 33 | 34 | SET @i:=0; 35 | 36 | 37 | SELECT @i:=@i+1 as rank,name,mark FROM students WHERE dept="$d" ORDER BY mark DESC; 38 | 39 | 40 | EOF`" 41 | 42 | 43 | echo "$result" 44 | 45 | 46 | echo 47 | 48 | 49 | done 50 | -------------------------------------------------------------------------------- /Chapter10/script8.txt: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | #Description: A user administration tool 5 | 6 | 7 | function usage() 8 | 9 | 10 | { 11 | 12 | 13 | echo Usage: 14 | 15 | 16 | echo Add a new user 17 | 18 | echo $0 -adduser username password 19 | 20 | 21 | echo 22 | 23 | 24 | echo Remove an existing user 25 | 26 | 27 | echo $0 -deluser username 28 | 29 | 30 | echo 31 | 32 | 33 | echo Set the default shell for the user 34 | 35 | 36 | echo $0 -shell username SHELL_PATH 37 | 38 | 39 | echo 40 | 41 | 42 | echo Suspend a user account 43 | 44 | 45 | echo $0 -disable username 46 | 47 | 48 | echo 49 | 50 | 51 | echo Enable a suspended user account 52 | 53 | 54 | echo $0 -enable username 55 | 56 | 57 | echo 58 | 59 | 60 | echo Set expiry date for user account 61 | 62 | 63 | echo $0 -expiry DATE 64 | 65 | 66 | echo 67 | 68 | 69 | echo Change password for user account 70 | 71 | 72 | echo $0 -passwd username 73 | 74 | 75 | echo 76 | 77 | 78 | echo Create a new user group 79 | 80 | 81 | echo $0 -newgroup groupname 82 | 83 | 84 | echo 85 | 86 | 87 | echo Remove an existing user group 88 | 89 | 90 | echo $0 -delgroup groupname 91 | 92 | 93 | echo 94 | 95 | 96 | echo Add a user to a group 97 | 98 | 99 | echo $0 -addgroup username groupname 100 | 101 | 102 | echo 103 | 104 | 105 | echo Show details about a user 106 | 107 | 108 | echo $0 -details username 109 | 110 | 111 | echo 112 | 113 | 114 | echo Show usage 115 | 116 | 117 | echo $0 -usage 118 | 119 | 120 | echo 121 | 122 | 123 | exit 124 | 125 | 126 | } 127 | 128 | 129 | if [ $UID -ne 0 ]; 130 | 131 | 132 | then 133 | 134 | 135 | echo Run $0 as root. 136 | 137 | 138 | exit 2 139 | 140 | 141 | fi 142 | 143 | 144 | case $1 in 145 | 146 | 147 | -adduser) [ $# -ne 3 ] && usage ; useradd $2 -p $3 -m ;; 148 | 149 | 150 | -deluser) [ $# -ne 2 ] && usage ; deluser $2 --remove-all-files;; 151 | 152 | 153 | -shell) [ $# -ne 3 ] && usage ; chsh $2 -s $3 ;; 154 | 155 | 156 | -disable) [ $# -ne 2 ] && usage ; usermod -L $2 ;; 157 | 158 | 159 | -enable) [ $# -ne 2 ] && usage ; usermod -U $2 ;; 160 | 161 | 162 | -expiry) [ $# -ne 3 ] && usage ; chage $2 -E $3 ;; 163 | 164 | 165 | -passwd) [ $# -ne 2 ] && usage ; passwd $2 ;; 166 | 167 | 168 | -newgroup) [ $# -ne 2 ] && usage ; addgroup $2 ;; 169 | 170 | 171 | -delgroup) [ $# -ne 2 ] && usage ; delgroup $2 ;; 172 | 173 | 174 | -addgroup) [ $# -ne 3 ] && usage ; addgroup $2 $3 ;; 175 | 176 | 177 | -details) [ $# -ne 2 ] && usage ; finger $2 ; chage -l $2 ;; 178 | 179 | 180 | -usage) usage ;; 181 | 182 | 183 | *) usage ;; 184 | 185 | 186 | esac 187 | -------------------------------------------------------------------------------- /Chapter10/script9.txt: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | #Description: A script for image management 5 | 6 | 7 | if [ $# -ne 4 -a $# -ne 6 -a $# -ne 8 ]; 8 | 9 | 10 | then 11 | 12 | 13 | echo Incorrect number of arguments 14 | 15 | 16 | exit 2 17 | 18 | 19 | fi 20 | 21 | 22 | while [ $# -ne 0 ]; 23 | 24 | 25 | do 26 | 27 | 28 | case $1 in 29 | 30 | 31 | -source) shift; source_dir=$1 ; shift ;; 32 | 33 | 34 | -scale) shift; scale=$1 ; shift ;; 35 | 36 | 37 | -percent) shift; percent=$1 ; shift ;; 38 | 39 | 40 | -dest) shift ; dest_dir=$1 ; shift ;; 41 | 42 | 43 | -ext) shift ; ext=$1 ; shift ;; 44 | 45 | 46 | *) echo Wrong parameters; exit 2 ;; 47 | 48 | 49 | esac; 50 | 51 | 52 | done 53 | 54 | 55 | for img in `echo $source_dir/*` ; 56 | 57 | 58 | do 59 | 60 | 61 | source_file=$img 62 | 63 | 64 | if [[ -n $ext ]]; 65 | 66 | 67 | then 68 | 69 | 70 | dest_file=${img%.*}.$ext 71 | 72 | 73 | else 74 | 75 | 76 | dest_file=$img 77 | 78 | 79 | fi 80 | 81 | 82 | if [[ -n $dest_dir ]]; 83 | 84 | 85 | then 86 | 87 | 88 | dest_file=${dest_file##*/} 89 | 90 | 91 | dest_file="$dest_dir/$dest_file" 92 | 93 | 94 | fi 95 | 96 | 97 | if [[ -n $scale ]]; 98 | 99 | 100 | then 101 | 102 | 103 | PARAM="-resize $scale" 104 | 105 | 106 | elif [[ -n $percent ]]; then 107 | 108 | 109 | PARAM="-resize $percent%" 110 | 111 | 112 | 113 | fi 114 | 115 | 116 | echo Processing file : $source_file 117 | 118 | 119 | convert $source_file $PARAM $dest_file 120 | 121 | 122 | done 123 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Packt 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 | ## $5 Tech Unlocked 2021! 2 | [Buy and download this product for only $5 on PacktPub.com](https://www.packtpub.com/) 3 | ----- 4 | *The $5 campaign runs from __December 15th 2020__ to __January 13th 2021.__* 5 | 6 | # Linux Shell Scripting Cookbook - Third Edition 7 | This is the code repository for [Linux Shell Scripting Cookbook - Third Edition](https://www.packtpub.com/networking-and-servers/linux-shell-scripting-cookbook-third-edition?utm_source=github&utm_medium=repository&utm_campaign=9781785881985), published by [Packt](https://www.packtpub.com/?utm_source=github). It contains all the supporting project files necessary to work through the book from start to finish. 8 | 9 | ## About the Book 10 | The shell is the most powerful tool your computer provides. Despite having it at their fingertips, many users are unaware of how much the shell can accomplish. 11 | 12 | Using the shell, you can generate databases and web pages from sets of files, automate monotonous admin tasks such as system backups, monitor your system's health and activity, identify network bottlenecks and system resource hogs, and more. 13 | 14 | This book will show you how to do all this and much more. 15 | 16 | This book, now in its third edition, describes the exciting new features in the newest Linux distributions to help you accomplish more than you imagine. It shows how to use simple commands to automate complex tasks, automate web interactions, download videos, set up containers and cloud servers, and even get free SSL certificates. 17 | 18 | Starting with the basics of the shell, you will learn simple commands and how to apply them to real-world issues. From there, you'll learn text processing, web interactions, network and system monitoring, and system tuning. 19 | 20 | Software engineers will learn how to examine system applications, how to use modern software management tools such as git and fossil for their own work, and how to submit patches to open-source projects. 21 | 22 | Finally, you'll learn how to set up Linux Containers and Virtual machines and even run your own Cloud server with a free SSL Certificate from letsencrypt.org. 23 | 24 | ## Instructions and Navigation 25 | All of the code is organized into folders. Each folder starts with a number followed by the application name. For example, Chapter02. 26 | 27 | 28 | 29 | The code will look like the following: 30 | ``` 31 | $> env 32 | PWD=/home/clif/ShellCookBook 33 | HOME=/home/clif 34 | SHELL=/bin/bash 35 | # ... And many more lines 36 | ``` 37 | 38 | The recipes in this book run on any Linux-based computer—from a Raspberry Pi to IBM Big Iron. 39 | 40 | ## Related Products 41 | * [Swift 3 Functional Programming](https://www.packtpub.com/application-development/swift-3-functional-programming?utm_source=github&utm_medium=repository&utm_campaign=9781785883880) 42 | 43 | * [iOS 10 Programming for Beginners](https://www.packtpub.com/application-development/ios-10-programming-beginners?utm_source=github&utm_medium=repository&utm_campaign=9781786464507) 44 | 45 | * [Swift 3 Protocol-Oriented Programming - Second Edition](https://www.packtpub.com/application-development/swift-3-protocol-oriented-programming-second-edition?utm_source=github&utm_medium=repository&utm_campaign=9781787129948) 46 | 47 | --------------------------------------------------------------------------------