Thanks for the reply Lars
I putted together a small script and are wondering how this can be improved.
Which i have NO doubt it can be My bash skills is extreamly rusty
Code:
#!/bin/bash
##This script looks for changes in the topology, from a source to a destination target.
##If a change happends it will be printed to the screen of the device that runs the script.
##The script takes two arguments [destination_target], [sleep_between_traceroutes]
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root" 1>&2
exit 1
fi
destination_target=${1}
sleep_between_traceroutes=${2}
run="1"
path1="/tmp/topologyChange1.txt"
path2="/tmp/topologyChange2.txt"
file1="0"
count="0"
echo "script start up"
if [ -e ${path1} ]; then
rm -v ${path1}
fi
if [ -e ${path2} ]; then
rm -v ${path2}
fi
while [ ${run} -eq 1 ]
do
let "count++"
echo "Script has runned ${count} times"
if [ ${file1} -eq 0 ]; then
traceroute -n -I ${destination_target} |awk '{print $2}' |sed '1d' > ${path1}
file1="1"
else
traceroute -n -I ${destination_target} |awk '{print $2}' |sed '1d '> ${path2}
fi
if [ -e ${path1} ] && [ -e ${path2} ]; then
echo "checking topology"
if [[ ! $(diff -s ${path1} ${path2}) == "Files /tmp/topologyChange1.txt and /tmp/topologyChange2.txt are identical" ]]; then
clear
echo "topology has changed"
diff -y ${path1} ${path2}
mv ${path2} ${path1}
else
echo "no topology change"
echo ""
fi
fi
sleep ${sleep_between_traceroutes}
done
exit 0
Bookmarks