error "integer expression expected" when selecting values

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

Post some lines of /var/www/cgi-bin/modems_failed and mention the value you want to grep for.

Regards

The lines of /var/www/cgi-bin/modems_failed are the excerpt collected by expect.

In that case, the device name is device1, so my script would select the line with failed modems Number of failed/non-existent modems: 10 and select the value 10

the output file would have a line written with device1 10

a little progress: the error is caused by CR/LF (0x0d/0x0a) characters at the end of line. the script works fine if the end of line is unix style, ending with LF only (0x0a)

I used the command dos2unix to convert the input file and now my script works as expected

so my question in fact is:

how can I grep/sed/cut an input file and leave behind the 0x0d characters?

I changed the extraction line from

BAD=$(cat /var/www/cgi-bin/modems_failed | grep -A16 $X | grep failed | cut -d " " -f 13 | grep "[^0-9]")

to

BAD=$(cat /var/www/cgi-bin/modems_failed | grep -A16 $X | grep failed | cut -d " " -f 13 | sed -e 's/\r$//')

the sed -e 's/\r$//' strips the CR characters and the script works as expected now.