Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
This week, we're updating our course layouts and descriptions. Presentation and materials always gently change over time, but just occasionally there's a need to make a step change to clear out some of the old and roll in the new. That's now happening - but over a long and complex site it's not instant and you'll see sections of the site changing up to and including 19th September.

See also [here] for status update
 
How to ssh and execute a particular command

Posted by chets (chets), 9 October 2007
HI,
im new to this TCL/TK programming, wanted to know how to spawn another m/c and execute command over there.
i want it from TK (window) instead of command line.

Can anyone help me in this, any example in Expectk would be  
helpful.

Thanks,
chets

Posted by admin (Graham Ellis), 9 October 2007
Here's an example with Expect (no Tk) which should help you with that end ...

Code:
#!/usr/bin/expect

# Using ssh from expect

log_user 0
spawn ssh -l trainee snowdrop
expect "sword: "
send "abc123\r"
expect "]$ "
send "uptime\r"
expect "]$ "
set igot $expect_out(buffer)

puts $igot


I tested that .. and it worked for me:

Code:
earth-wind-and-fire:~/oct07 grahamellis$ ./exp_ssh
uptime
17:13:20 up  2:15,  3 users,  load average: 0.33, 0.17, 0.19
[trainee@snowdrop ~]$
earth-wind-and-fire:~/oct07 grahamellis$





Posted by chets (chets), 10 October 2007
Thanks a lot for the response... i got it and implemented in my setup it worked fine in CLI.
eg:
set Machine $src
set Password "nextone"
spawn ssh $Machine
expect "Password:"
send "$Password\n"
expect "inex:~ # "
send "cd /root/tools/sipp/\n"
expect "inex:~/tools/sipp # "
send "./sipp -sn uas\n"
interact

but rather than cli i wanted to spawn a window in GUI, i heard about expectk would help in this.
any example/ regarding expectk would be heplful...

Thanks,
Chets

Posted by admin (Graham Ellis), 10 October 2007
We have loads of Tk examples starting here. Individual bits of source code on each topic in the middle column, new topics across to the right.

Posted by chets (chets), 11 October 2007
well Thanks again.
i followed one of the example and written a script for ssh it worked.
#!/usr/bin/expectk

proc getfiles {host} {
      log_user 0
      set id [spawn ssh $host]
      expect "Password: "
      exp_send "abcd\n"
      expect "d123:~ # "
        interact
      }

set hostname "computer name"
entry .host -textvariable hostname

button .do -text go -command {
      getfiles $hostname
            }

pack .host .do

but here once the script is run through terminal and after entering comp IP and hit go button it spawns ssh in the same terminal

i want to pop up new window where it should spawn ssh
i used toplevel but din't worked.

any idea on this would be help ful




This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2014: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho