From b2a363ccd517a4c2649b22612c8f3fdeb84ed4fd Mon Sep 17 00:00:00 2001 From: Jack-Benny Persson Date: Mon, 30 Dec 2013 13:36:13 +0100 Subject: [PATCH] Lab8e8 - Wrote a small configuration script for failed_logins.sh --- configure.sh | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/configure.sh b/configure.sh index 2d8e5af..97c199d 100755 --- a/configure.sh +++ b/configure.sh @@ -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