One of the easiest ways to check Cisco configuration file quality is using shell script.
Our script will parse output to see if the following keywords are in the configuration file: "version", "show running-config", "begin", and "end".
If not all of the keywords found, then it will print the name of the file.
#!/bin/bash
for TEMPFILE in *
do
TEMPCOUNT=0
egrep "^(version|#version)" $TEMPFILE > /dev/null
RETVAL=$?
[ $RETVAL -eq 0 ] && TEMPCOUNT=`expr $TEMPCOUNT + 1`
egrep "^(show running-config|begin)" $TEMPFILE > /dev/null
RETVAL=$?
[ $RETVAL -eq 0 ] && TEMPCOUNT=`expr $TEMPCOUNT + 1`
egrep "^(end)" $TEMPFILE > /dev/null
RETVAL=$?
[ $RETVAL -eq 0 ] && TEMPCOUNT=`expr $TEMPCOUNT + 1`
if [ $TEMPCOUNT -ne 3 ]; then
echo $TEMPFILE
fi
done
In another example, we just look for "version" keyword.
#!/bin/bash
for TEMPFILE in *
do
egrep "^(version|#version)" $TEMPFILE > /dev/null
RETVAL=$?
[ $RETVAL -eq 0 ] && echo Found sting in $TEMPFILE
[ $RETVAL -ne 0 ] && echo No string found in $TEMPFILE
done
We have 7 guests and no members online