I'm trying to code an script that takes IP addresses from a .csv file and telnet the device to catch "show version" command output.
So far I have coded this:
#!/bin/bash
#!/usr/bin/expect -f
FILE1=dispositivos.csv #file with IP's and device name
set Username "user" #this is the user for telnet connection.
set Password "this.is.the.pass" #pass for telnet connection.
NUMERODISP="$(wc -l $FILE1 | awk '{print $1}')" #this command counts number of devices (IP's) in the file as it is a .csv file, it only counts number of lines.
for i in `seq 2 $NUMERODISP`;
do
IP="$(awk -vnum="$i" 'NR == num { print $NF }' dispositivoss.csv)"
echo "$IP" #this takes the IP from last column from .csv file
done
I need to complete the for loop so it connect via telnet to the IP stored at $IP and save "show version" output.
I have tried with this:
for i in `seq 2 $NUMERODISP`;
do
IP="$(awk -vnum="$i" 'NR == num { print $NF }' dispositivoss.csv)"
send "telnet $IP\r"
expect "Username:"
send "$Username\r"
expect "Password: "
send "$Password\r"
expect "*>"
send "show version\r"
log_file -noappend SN_$IP.dat;
expect -ex "--More--" {send -- " "; exp_continue}
expect "*>"
log_file;
done
but it didn't work.
Is this cause I cannot use bash and expect?
In case that's the reason.. how can I send $IP and $NUMDISP as a variable into a different expect script? (this is why I think it's different than the other question)
expectcan read a CSV file, like I showed in unix.stackexchange.com/questions/350338/…