Showing progress as shell script runs

92 views Asked by At

I would like to display something showing that the script is still gathering information from a device. Whether it be hash marks or periods. As you can see below when it starts its walk of a device it echos its start time. It is here I would like to show that something indicating its still running.

#!/bin/sh
#Create nbar directory in the /opt
#Change diretory to /opt/nbar
#Create file to be read from it needs to be in the following format.
#The only white space in the file that is allowed is between the columns
#column 1 the IP address
#column 2 the SNMP community string
#column 3 the state
#column 4 the city
#Eample: 10.0.0.1 public Cisco RTP
#
#Get file to read
echo "What file should be used?"
read input_variable
echo "Ok using $input_variable"
if [ -e $input_variable ]
then
while read field1 field2 field3 field4
do
curdate=`date "+%Y%m%d%H%M"`
fname=$field3-$field4-$field1-$curdate.nbar
#Tell me what device you started
echo Now querying $field3-$field4 started at `date "+%T"`
#Create file
echo $field3-$field4-$curdate $'\n' > $fname
#Confirm System Name
snmpwalk -v2c -c $field2 $field1 1.3.6.1.2.1.1.5  >> $fname
#Insert blank line
echo >> $fname
#Get IOS version
snmpget -v2c -c $field2 $field1 1.3.6.1.2.1.1.1.0  >> $fname 
#Insert blank line
echo >> $fname
#Get system uptime
snmpwalk -v2c -c $field2 $field1 1.3.6.1.2.1.1.3  >> $fname
#Insert blank line
echo >> $fname
#Get nbar protocol table  
snmptable -v2c -c $field2 $field1 -m ALL 1.3.6.1.4.1.9.9.244.1.2.1 >> $fname
#close target file
done </opt/nbar/$input_variable
#Create zip file
for file in *.nbar
do
zip "nbar$curdate.zip" "$file"
done
#Cleanup individual files
rm -rf /opt/nbar/*.nbar
else
echo No such file.
fi

Other than my question this is a functional script to poll Cisco devices. If you understand SNMP MIBs and OID's you can change there values as you need. Enjoy! :)

1

There are 1 answers

4
Nathan Wilson On BEST ANSWER

This will print a dot to the screen every second. Add these lines just before the first snmpwalk command.

while true; do echo -n . ; sleep 1 ; done &
pid=$!

#do time consuming tasks here

Then to stop printing the dots, add this line just after the last snmpwalk command.

kill $pid