#!/usr/bin/expect -f
trap {
set XZ [stty rows ]
set YZ [stty columns]
stty rows $XZ columns $YZ < $spawn_out(slave,name)
} WINCH
proc getpass pwprompt {
set oldmode [stty -echo -raw]
send_user "\n $pwprompt"
set timeout -1
expect_user -re "(.*)\n"
send_user "\n"
eval stty $oldmode
return $expect_out(1,string)
}
set host [lrange $argv 0 0]
#Save Last Path ########
set last_path_file "/tmp/.save_bala_ssh_$host.txt"
if {[file exists $last_path_file]} {
set f [open "/tmp/.save_bala_ssh_$host.txt"]
set lp [split [read $f] "\n"]
set last_path [lindex $lp 1]
send_user "Last Path for host $host: $last_path\n"
close $f
}
########################
#set user [lrange $argv 1 1]
set user "usuario_balabit"
set path [lrange $argv 1 1]
#set pass [getpass "Password: "]
set pass "senha_balabit"
set timeout -1
#spawn -noecho bash;
#send "ssh -A $host\r"
spawn ssh -t $host
set passwords { "senha1" "senha2" "senha3" }
set try 0
##
set timeout 2
expect {
"Gateway username: " {
send -- "$user\r"
exp_continue
}
"Gateway password: " {
send -- "$pass\r"
exp_continue
}
"password:" {
if { $try >= [llength $passwords] } {
send_error ">>> wrong passwords\n"
exit 1
}
send -- "[lindex $passwords $try]\r"
incr try
set timeout 3
exp_continue
}
"denied" {
set timeout 5
exp_continue
}
timeout {
#interact
send_user "\nOK Cool! Finally Connected\n"
if { $path != "" } {
if { $path != "-l" } {
send -- "\nclear\ncd $path\n"
} else {
send -- "\nclear\ncd $last_path\n"
}
}
#interact
set CTRLZ \032
interact {
-reset $CTRLZ {exec kill -STOP [pid]}
#\003 exit
#mostra_data {
# send_user "The date is [exec date]."
#}
#foo {
# send_user "bar"
#}
#\001 {send_user "you typed a control-A\n";
# send "\001"
#}
#\002 {send_user "you typed a control-B\n";
# send "\002"
#}
ç {
send "pwd\r"
expect "/*\n"
puts [open $last_path_file w] $expect_out(buffer)
}
}
}
}
No comments:
Post a Comment