hello,
i made a routine in expect that connects via ssh to a juniper firewall, makes a backup of the configuration and saves it into a text file, so far it's working fine, and since it was working so fine i decided to add it to cron in order to run it automatically every 14 days.
but now i have a problem, i use the standard output in order to save the text file, but when the script reads the text file that contains the ips of the firewalls its supposed to connect to, it saves the configuration of the last firewall it connected, i mean, i want it to save all the configurations of all the firewalls it connects.
heres the expect script
#!/usr/bin/expect -f
#
set arch [open ip.txt r]
while {[gets $arch LINEA] >= 0} {
set IP [lindex $LINEA 0]
set USER [lindex $LINEA 1]
set PASSWORD [lindex $LINEA 2]
set COM [lindex $LINEA 3]
set PROMPT [lindex $LINEA 4]
}
set force_conservative 0 ;# set to 1 to force conservative mode even if
;# script wasn't run conservatively originally
if {$force_conservative} {
set send_slow {1 .001}
proc send {ignore arg} {
sleep .1
exp_send -s -- $arg
}
set timeout 2
puts "\n"
#
spawn $COM $IP
expect {
-exact "conection refused" {puts "\n";exit}
-exact "Host name lookup failure" {puts "\n";exit}
-exact "Name (localhost:root):*"
}
send -- "$USER\r"
expect "password:"
send -- "$PASSWORD\r"
expect -exact "$PROMPT"
send -- "get config\r"
send -- "show test\r"
expect {
-exact "more" {send -- "\r";exp_continue}
"$PROMPT" {}
}
puts "\n"
exit
and here's how i get the standard output
expect firewall.exp > javier-$(date +%d%b%Y).txt
and here's the ip.txt in wich i store the ip's of the firewalls
192.168.127.1 javier javier telnet >
192.168.127.2 javier javier ssh >
i was kind of hoping anyone could help me to store all the configuration of all the firewalls instead of overwriting in the same text file....please!!!! :-|