expect: send many commands to routers and such

A neat script I pieced together - to send many commands (f.ex. deletion of objects etc.) to a box (using ssh) - input from a file (remember to atleast use a proper random name for the file etc. :)


#!/usr/bin/expect -f
set timeout 20
set Machine [lindex $argv 0]
set infilename [lindex $argv 1]
set infile [open $infilename r ]
spawn ssh -l username $Machine
expect {
 -re "Are you sure you want to continue connecting" { send "yes\n" }
 -re "Password:" { send "password\n" }
}
while {![eof $infile]} {
  gets $infile line
  expect  -re "\r\n>" { send -- "$line\n" }
}
exit

 

1 comments on expect: send many commands to routers and such

  1. Anonymous
    Tue, 07/23/2013 - 15:35
    Thanks for the pointer works good for me..