1

I need to get the serial number of some devices listed in a file like this:

device_id,ip_address
 BIOTERIO, 148.000.00.189
 N7K-LAN(JAF1651ANDL), 148.000.0.192
 LAB_PESADO, 148.000.000.130
 Arquitectura_Salones, 148.000.000.61
 CIVIL_253, 148.000.000.253 
 Arquitectura, 148.000.000.253
 ING_CIVIL, 148.000.000.251
 ING_CIVIL_DIR, 148.000.0.188
 Ingenieria_Posgrado, 148.000.000.253
 Biblio_Barragan, 148.000.000.61
 Electronica_Edif_3, 148.000.000.253

I don't know how to make the loop, but I need it to connect via telnet to each device, with a certain username and pass, then run this cisco command "show version" and save the serial number in the same file (if possible).

Any idea how can I do it?

1 Answer 1

0
#!/usr/bin/env expect

# open first argument to program...
set fd [open [lindex $argv 0]]

# for each line using that file handle...
while {[gets $fd line] >= 0} {
    # split on , and select the last one...
    set lastcolumn [lindex [split $line ","] end]
    # whoops there's some whitespace so clear that...
    set ip [string trim $lastcolumn " "]
    puts ">$ip<"
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .