dear members,
I am having some difficulties with an automation script that I am writing.
We have equipments deployed over our network that generate status messages and I was trying an automated method to collect all information.
I did a expect script that telnet all devices, logs, asks for the status and save it to a file.
My next step is read that file, check for the faulty devices and write only the faulty devices names to a file.
an excerpt from the file that expect collects is like this:
root@lemure cgi-bin]# telnet device1
Trying xxx.yyy.zzz.ttt...
Connected to device1.
Escape character is '^]'.
(device1) Enter password:
User: admin
Password:
Number of available modems: 952
Number of disabled modems: 0
Number of failed/non-existent modems: 10
Number of available good modems: 816
Number of in-use modems: 8
Number of all possible modems: 960
Number of suspect modems: 136
Connection closed by foreign host.
my bash script is like that:
#!/bin/sh
for X in $(cat /var/www/cgi-bin/devices_bd) # devices_bd is a list with all devices
do
BAD=$(cat /var/www/cgi-bin/modems_failed | grep -A16 $X | grep failed | cut -d " " -f 13 | grep "[^0-9]")
echo $BAD >> /var/www/cgi-bin/teste.bad.var
if [ $BAD -gt 0 ]
then echo $X $BAD >> /var/www/cgi-bin/teste.bad
fi
done
that script checks if there are failed modems in the device. If there are, the device is listed with the number of filed modems in a separate file.
when I run that scrip I got : integer expression expected errors. I was assumin that they where caused by CR/LF characters (0x0d and 0x0a), but the way I did the grep I don't think that should happen
I also tried selecting the digits with sed, like that:
BAD=$(cat /var/www/cgi-bin/modems_TNT | grep -A16 $X | grep failed | cut -d " " -f 13 | sed 's/ //g')
same error.
I think that I am commiting some very basic mistake, but I don't have much expertise with scripts.
Any sugestion is appreciated
TIA,
orlando