| |||||||||||
Exiting from interact (Expect) Posted by enquirer (enquirer), 2 May 2005 I need a small clarification. That's I'm using a Telnet server (Proxy Server) to access external FTP sites.If i need to do a ftp, then first i should log in to the Telnet Server and from there i need to select a option whether to upload or download the files. If i'm going to upload then i need to fill up a form which should filled up manually, after that again my proxy server requires my passwd and then i can use the FTP service. Using the EXCPECT scripting i've entered till option upload or download and there i've used a INTERACT for manual data entering. Now my query is to run the script after entering the data, thats to UN-INTERACT the process and return to my expect script. If possible kindly help me on this regards. Posted by admin (Graham Ellis), 2 May 2005 Interact is used to provide a "pipe" through your application from your keyboard to the system / process to which you've established contact; apart from anything specified when you start your intereact command, it's going to pass through and pass back anything that you type or the remote process generates. In other words, you need to tell interact how it's to exit before you start it running, and it will monitor for that string.For example: interact +++ return will start interact, and it will continue providing the connection to you until a stream of three "+" characters is encountered ... at which time it will return to your Expect script which will carry on. If you wish to have your interact return to you on the completion of an ftp operation, you could use interact ftp> return The -o option to interact allows you to specify an EOF action - i.e. what interact is to do if the remote process terminates or drops the connection, and this can include a return ... although if you don't specify it, it's added by default anyway (after all, what else could interact do?) interact -o eof return Posted by bharaniks (bharaniks), 3 May 2005 Hi Graham Ellis,I really Thankyou a lot, for the help and sorry to disturb you again. One more query, i've dropped the script file in path /usr/bin and given permission as 750 thats the root has "7", group users has "5" and other users has "0" now the user can execute the script, right. But also the user can view the file by "cat /usr/bin/script" but the user should not view the file and only they should execute the script. I belive that if the permission is set only to "1" then the user cannot execute the script. Kindly help me on this regards. Thanksyou once again. - Bharani Posted by admin (Graham Ellis), 3 May 2005 The "x" permission bit is used to control whether a script can be executed and the "r" permission bit to control whether it's readable. If you were to attend one of my Linux courses, I would STRONGLY advise you to use the letters rather than the numbers if at all possible to set permissions ... but if you must use numbers then, yes0 - no access 1 - execute only 4 - read only 5 - both read and execute Posted by bharaniks (bharaniks), 3 May 2005 Hi Graham Ellis,Thankyou for the information. Yes, i've planned to attend a Linux course to gain a better knowledge but for next 4weeks its not possible because with in a month my project should be completed. Would be better if it can be started after a month. For this issue how can i solve it ? My requirement is to run the script alone but not to be viewed by the user. Can you please suggest me if there is any other option. Hope you will provide me a Positive result. Regards Bharani Posted by admin (Graham Ellis), 3 May 2005 I would be tempted to suggest that you have the script owned and run by a different user if that's possible ... and this might be a case for using "setuid". However - get that wrong and you can introduce more security issues than you fix. A thought - you don't have the Expect script running on a web server do you? If you were to use a web front end, the user wouldn't be able to see the script. There's an example at http://www.wellho.net/resources/ex.php4?item=t212/livetest.exp ... of course, I've intentionally shown you the source code in this case Posted by doublea1535 (doublea1535), 16 August 2006 I am having trouble getting interact to return based on data coming from a spawned ssh session. It works when I type the value to return on, but not when this text is received on the terminal....#!/usr/local/bin/expect if {"$argv" == ""} { puts "You must specify the name of the firewall that you wish to pull session info from";exit 1 } set name $argv set logfile /tmp/$name.session set ipfile /tmp/$name.ip set sortfile /tmp/$name.sort log_user 0 spawn ssh admin@$name log_user 1 expect "assword" interact Console return log_user 0 expect "$name" { send "get session\r" } log_file -a -noappend $logfile expect "sessions" { send "exit\r" } log_file set timeout 300 exec awk {/->[0-9]/} $logfile | sed {s/.*://} | sed {s/\/.*//} > $ipfile set uipfile [exec sort $ipfile | uniq] foreach ip $uipfile { exec echo -n "[exec grep -c $ip $ipfile] - " >> $sortfile exec echo $ip >> $sortfile } puts [exec sort -gr $sortfile] exec rm $logfile $ipfile $sortfile I want expect to wait to be prompted for a password, then turn the script over to the user who will enter the password. Once the user has entered the password the string "Console" appears on the terminal. Once this occurs I want expect to start re-running the script. It is not working as planned however. If I type "Console" it works, but not when the output is sent from the device I am connecting to. Posted by doublea1535 (doublea1535), 16 August 2006 Nevermind, I found the answer. The -o option will do it.interact -o "output_from_spawned_process" return 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 |