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
For 2021 - online Python 3 training - see ((here)).

Our plans were to retire in summer 2020 and see the world, but Coronavirus has lead us into a lot of lockdown programming in Python 3 and PHP 7.
We can now offer tailored online training - small groups, real tutors - works really well for groups of 4 to 14 delegates. Anywhere in the world; course language English.

Please ask about private 'maintenance' training for Python 2, Tcl, Perl, PHP, Lua, etc.
How to ssh and execute a particular command

Posted by chets (chets), 9 October 2007
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  


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


# 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:

earth-wind-and-fire:~/oct07 grahamellis$ ./exp_ssh
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.
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"

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...


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.

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

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 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., 2022: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: • WEB: • SKYPE: wellho