6 apr 2006 kl. 23.07 skrev Doug McNutt: At 14:05 -0600 4/6/06, Gnarlodious wrote: Allegedly there is an app out there that allows scripts to interact with the shell. I think it is called Expect.
Expect is an addition to Tcl. Tcl (pronounced tickle) is a scripting addition that operates under a shell and extends the scripting language. Expect allows you to wait for an expected reply from a remote host, password? for instance, as applied to ssh. Raw FTP involves a lot of that.
Because Do Shell Script starts up a new shell each time it is executed I doubt that Tcl or Expect can contribute much.
Well he could do something like running the script below via
do shell script "/usr/bin/expect -f /path/to/script/below/do_remote.tcl mypass r_user r_pass ssh_server ssh_port "
appended output below script
#!/usr/bin/expect set Version "0.0.1" #----------------------------------------- proc Do_Remote {Local_Password Remote_User Remote_Password Ssh_Server Ssh_Port} { global timeout set timeout 5 ; # Timeout for connecting in seconds set Logged_In 0 if {[string equal $Local_Password ""]} { spawn ssh -p $Ssh_Port $Remote_User@$Ssh_Server } else { spawn sudo ssh -p $Ssh_Port $Remote_User@$Ssh_Server # Password for the sudo, ie local users password. But is it needed to run ssh via sudo? expect { *ssword: {send "$Local_Password\r" ;# root@ipcop's password} timeout {return 101 } } } # Password for the remote machine, for user Remote_User expect { *ssword: {send "$Remote_Password\r" ;# root@ipcop's password} # * {return 104} timeout {return 105 } } expect { \nLast* {set Logged_In 1 ;#Last login: Wed Jan 11 18:57:34 2006} \nPermiss* {puts stderr "Wrong password" return 106} timeout {return 107 } } if {$Logged_In} { # do something here, on remote server, / send "uname\r" expect { \nLinux {puts "Penguin"} \nDarwin {puts "Hexley"} timeout {return 108 } } } send "exit\r" return 0 } #-----------------------------------------
#Usage #do_remote.tcl Local_Password Remote_User Remote_Password Ssh_Server Ssh_Port
#Begin
set L_P [lindex $argv 0] set R_U [lindex $argv 1] set R_P [lindex $argv 2] set S_S [lindex $argv 3] set S_P [lindex $argv 4]
set Result [Do_Remote $L_P \ $R_U \ $R_P \ $S_S \ $S_P ]
# Pass on exitcode to shell exit $Result
#------------
results in
minimac: bnl$ /do_remote.tcl "" root secret_password ipcop 222 spawn ssh -p 222 root@ipcop root@ipcop's password: Last login: Fri Apr 7 00:17:23 2006 from minimac.lundin.homelinux.net uname root@ipcop:~ # uname Linux root@ipcop:~ # Penguin minimac: bnl$
/Björn
Björn Lundin bnl at spray dot se
|