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 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
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., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho