| |||
| [Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] |
6 apr 2006 kl. 23.07 skrev Doug McNutt:
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 |
_______________________________________________ Do not post admin requests to the list. They will be ignored. Applescript-users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/applescript-users/email@hidden This email sent to email@hidden
| References: | |
| >Re: Do shell and ssh (From: Gnarlodious <email@hidden>) | |
| >Re: Do shell and ssh (From: Doug McNutt <email@hidden>) |
| Home | Archives | FAQ | Terms/Conditions | Contact | RSS | Lists | About |
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE
Contact Apple | Terms of Use | Privacy Policy
Copyright © 2007 Apple Inc. All rights reserved.