Lab8e8 - Wrote a small configuration script for failed_logins.sh

This commit is contained in:
Jack-Benny Persson 2013-12-30 13:36:13 +01:00
parent 886e2cc406
commit 87f788afa4
2 changed files with 44 additions and 3 deletions

View File

@ -4,10 +4,14 @@
# LX13
# Configuration script to update the hardcoded binaries
# Variables
Binaries=(sed awk egrep mail printf cat grep mktemp rm tail)
File="failed_logins.sh"
TempFile=`mktemp -t failed_logins.XXXXXX`
StartBin=8
EndBin=17
# Check that they are all installed
for bin in ${Binaries[@]}; do
whereis $bin | awk '{ print $2 }' | grep $bin &> /dev/null
if [ $? -ne 0 ]; then
@ -16,6 +20,33 @@ for bin in ${Binaries[@]}; do
fi
done
for i in ${Binaries[@]}; do
# Make a temporary copy of the original file
cp $File $TempFile
# Loop through all the binaries to extract the path and make new
# variables for the script looking like this: Binary="/bin/binary"
Index=0
for i in ${Binaries[@]}; do
NewBins[$Index]=$(echo "$i=\"`whereis $i | awk '{ print $2 }'`\"" | \
sed "s/\b\(^.\)/\u\1/g")
((Index++))
done
# Replace the old variables for the new ones
cat $TempFile | sed "{
/Sed=/c${NewBins[0]}
/Awk=/c${NewBins[1]}
/Egrep=/c${NewBins[2]}
/Mail=/c${NewBins[3]}
/Printf=/c${NewBins[4]}
/Cat=/c${NewBins[5]}
/Grep=/c${NewBins[6]}
/Mktemp=/c${NewBins[7]}
/Rm=/c${NewBins[8]}
/Tail=/c${NewBins[9]}
}" > $File
# Clean up
rm $TempFile
exit 0

10
Labb8/ovning8.md Normal file
View File

@ -0,0 +1,10 @@
# Exercise 8, lab 8 #
This exercise was about writing a nice little script that you find useful.
Only requierment was that it should use sed and/or awk.
So for this exercise I've written the following script(s).
* [configure.sh](https://github.com/jackbenny/scripts_grundkurs/blob/master/Labb8/ovning5/configure.sh)
- A small script that configures failed\_logins.sh with new variables
for the hardcoded binary pathes. Useful in case this script is being run
a different distro which doesn't have the same pathes as Ubuntu.