I would be happy to close this thread once it is solved.
I am trying to find the device type eg cisco maipu zyxel etc using bash script and expect..
till now what i have done is that my script checks vty connections to a device .. runs show version command and saves everything in a temp file which is named the same as the ip address of the device.
also makes a result file which has something like this
device ip vty status
--------- ----------
--------- ----------
etc
the files in temp are such that
filename 127.0.0.1
cisco if show version output cisco
or zyxel or so on ...
what i need to do is to grep the pattern "cisco / zyxel / maipu" if it exists in the file of specific device ( named same as ip address ) and put the device type in the new result file such that
device ip vty status device type
--------- ----------- ----------
---------- --------- ------------
Code:
cd "$temp" || exit 1
while read file; do
while read line; do
if [ ! `grep --silent Cisco "$temp/$file" | echo "$?"` ] ; then
echo -n "$line cisco"
continue
elif [ ! `grep --silent Maipu "$temp/$file" | echo "$?"` ] ; then
echo -n "$line maipu"
continue
elif [ ! `grep --silent V3.90 "$temp/$file" | echo "$?"` ] ; then
echo -n "$line zyxel3.90"
continue
else
echo -n "$line Invalidtype"
continue
fi
done < "$HOME/Desktop/autotel/temp1/RESULT" > "$HOME/Desktop/autotel/temp1/FINALRESULT"
done <<< $(ls -1)
grep can not match the single ip address one by one..
Code:
grep: /home/noc/Desktop/autotel/temp/10.169.247.34 10.173.73.1 10.173.73.254 71.11.162.253 71.11.162.254: No such file or directory
grep: /home/noc/Desktop/autotel/temp/10.169.247.34 10.173.73.1 10.173.73.254 71.11.162.253 71.11.162.254: No such file or directory
grep: /home/noc/Desktop/autotel/temp/10.169.247.34 10.173.73.1 10.173.73.254 71.11.162.253 71.11.162.254: No such file or directory
grep: /home/noc/Desktop/autotel/temp/10.169.247.34 10.173.73.1 10.173.73.254 71.11.162.253 71.11.162.254: No such file or directory
grep: /home/noc/Desktop/autotel/temp/10.169.247.34 10.173.73.1 10.173.73.254 71.11.162.253 71.11.162.254: No such file or directory
grep: /home/noc/Desktop/autotel/temp/10.169.247.34 10.173.73.1 10.173.73.254 71.11.162.253 71.11.162.254: No such file or directory
grep: /home/noc/Desktop/autotel/temp/10.169.247.34 10.173.73.1 10.173.73.254 71.11.162.253 71.11.162.254: No such file or directory
grep: /home/noc/Desktop/autotel/temp/10.169.247.34 10.173.73.1 10.173.73.254 71.11.162.253 71.11.162.254: No such file or directory
grep: /home/noc/Desktop/autotel/temp/10.169.247.34 10.173.73.1 10.173.73.254 71.11.162.253 71.11.162.254: No such file or directory
grep: /home/noc/Desktop/autotel/temp/10.169.247.34 10.173.73.1 10.173.73.254 71.11.162.253 71.11.162.254: No such file or directory
grep: /home/noc/Desktop/autotel/temp/10.169.247.34 10.173.73.1 10.173.73.254 71.11.162.253 71.11.162.254: No such file or directory
grep: /home/noc/Desktop/autotel/temp/10.169.247.34 10.173.73.1 10.173.73.254 71.11.162.253 71.11.162.254: No such file or directory
grep: /home/noc/Desktop/autotel/temp/10.169.247.34 10.173.73.1 10.173.73.254 71.11.162.253 71.11.162.254: No such file or directory
grep: /home/noc/Desktop/autotel/temp/10.169.247.34 10.173.73.1 10.173.73.254 71.11.162.253 71.11.162.254: No such file or directory
grep: /home/noc/Desktop/autotel/temp/10.169.247.34 10.173.73.1 10.173.73.254 71.11.162.253 71.11.162.254: No such file or directory
this is the final output file..
Code:
10.173.73.254 - vty login ok - version - eth0 - admin - 1234
Invalidtype10.169.247.34 - vty login ok - version - eth0 - tulipadmin - pl3p30tcnoc
Invalidtype71.11.162.253 - vty login ok - version - eth0 - admin - 1234
Invalidtype71.11.162.254 - vty login ok - version - eth0 - admin - 1234
Invalidtype10.173.73.1 - vty login failed
Invalidtype
in my final output file
instead of
bla bla bla bla bla router type
bla bla bla bla bla router type
i get
bla bla bla bla bla
routertype bla bla bla bla
router type bla bla
and it shows invalid type because grep was not able to match. . please help me fix this code
and no need to fret.. these are PRIVATE ip addresses for which i have explicit permission to test this script on
Update
Code:
10.173.73.254 - vty login ok - version - eth0 - admin - 1234^M Invalidtype
10.169.247.34 - vty login ok - version - eth0 - tulipadmin - pl3p30tcnoc^M Invalidtype
71.11.162.253 - vty login ok - version - eth0 - admin - 1234^M Invalidtype
71.11.162.254 - vty login ok - version - eth0 - admin - 1234^M Invalidtype
10.173.73.1 - vty login failed^M Invalidtype
FINALRESULT (END)
this is just ^M chars which i will remove to get the final file so one issue is resolved.. now please help me match the grep patter so that it displays the correct device type