| |||||||||||
How to spawn a session in new window using expectk Posted by chets (chets), 16 October 2007 HI,im using expectk to ssh a session, but it spawns it on the terminal on which script is run. i want to spawn a session in new window every time i do a ssh. Any idea would be helpful. 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 "# " interact } set hostname "computer name" entry .host -textvariable hostname button .do -text go -command { getfiles $hostname } pack .host .do Posted by admin (Graham Ellis), 16 October 2007 You can use new toplevel widgets to spawn new windows, and put your expect-ed results in therePosted by chets (chets), 16 October 2007 i tried with toplevel, but failed to get anything in new window.the output of ls is coming from terminal where this script is run. toplevel .messpop -width 30c -height 30c set timeout 3 set id [spawn ssh $host] set spid [ expect { "Are you sure you want to continue connecting (yes/no)?" { exp_send "yes\n";exp_continue } "Password: " { exp_send "abcd\n";exp_continue } "#" { exp_send "ls\n" ; interact } timeout { puts " Timed out ";exit } } ] text .messpop.msg -text $spid pack .messpop.msg pls correct me if anything is wrong with the script. Posted by chets (chets), 17 October 2007 Actually what i want here is spawning (ssh) two session within a single script.when my script is run (i.e. when button is clicked) i want two diff windows having saperate session(ssh). i don't know how to achieve this using expectk, is there some way to do this -> spawning two process with in one script. Posted by admin (Graham Ellis), 17 October 2007 on 10/17/07 at 05:51:45, chets wrote:
There are about 10 examples at http://www.wellho.net/resources/T212.html Posted by chets (chets), 17 October 2007 HI,got the thing how to spawn ssh in new window, we can use xterm here. eg: xterm -e ssh root@hostname will open new window asking for password. now i got stucked b/w xterm & expect when i click button im getting a new window asking for password, but i want to proceed without manually entering password. i.e. i'll provide password using expect in script but this is not working: spawn xterm -e ssh $hostname expect "Password: " exp_send "abcd\n" expect "# " interact on executing this a new window will open,but it hungs asking for password i don't know is expect is not working or exp_send is not sending password can anyone help in this, i want to enter without entering password (as i sent it in script itself) Posted by admin (Graham Ellis), 17 October 2007 Have you tried it with \r rather than \n on the end of the password? A carriage return rather than a line feed?Posted by chets (chets), 18 October 2007 Hi Graham,i tried with \r this time also not working, a window pop up and asks for password. have one doubt here by executing xterm -e ssh hostname it will pop up new terminal and asks for password. can we pass password using expect here. as xterm is new process is it possible i tried with this but didn't work: log_user 0 set timeout 3 set id [exec xterm -e ssh $host] expect -i $id -re "Password: " exp_send -i $id "abcd123\r" interact don't know how to pass that password, require help in this pls... Posted by admin (Graham Ellis), 18 October 2007 You do need spawn rather than exec if you're doing to expect from the id.If you run with log_user 1, what does that tell you? Posted by chets (chets), 19 October 2007 Hi Graham,now also same problem, it hungs and asks for password script: log_user 1 set timeout 3 set id [spawn xterm -e ssh $host] expect -i $id -re "Password: " exp_send -i $id "abcd1234\r" interact when i run this script in the terminal i observed(as log_user is 1): [root@d189 tcltk]# ./remote2ssh.tcl spawn xterm -e ssh 10.0.33.50 i think im missing some thing don't know how to send that password to the new terminal (xterm window) 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.
|
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |