1f7d
| |||||||||||
| |||||||||||
|
help with redirectioning output Posted by pmnf (pmnf), 22 July 2004 I ppl im new to expect and to this forum. this as you can see my first post of many ![]() My problem is the folowing. i want to connect to a remote machine via telenet run a script name extract.sh grab the output of the script and store it in a file. In this moment i am doing the folowing #!/usr/bin/expect -f # log_file -a MY_OUTPUT set user xpto set password xpto set site remote.address.pt set VAR 1 set T 0 spawn telnet $site while {$VAR>0} { #puts $VAR expect { "login:" { set rcvd $expect_out(buffer) send "$user\r" } "$user's Password:" { send "pulso.2\r" send "\n" send "cd nagios ;" set rcvd $expect_out(buffer) expect { "bash#" { send "./extract.sh\r" } } } } if {$T>3} exit incr T } exit ############ this is working but i think this isnt very good programing. what i really want to do is to run the program like this $ program.excpt >> AFILE & "AFILE : contains the result of the extract.sh Any ideas Posted by admin (Graham Ellis), 23 July 2004 I think you want to a) start with log_user 0 to turn off echo to stdout of all the text that comes back before you run your ./extract.sh b) add an extra expect after your send ./extract.sh to cause expect to wait for the next shell prompt, then when you have it add a puts $expect_out(buffer) to send your output to stdout ... which your >> will cause to be redirected onto the end of the file at runtime. You may need / want to puts an extra newline, datestamp, or header too so that you can easily analyse your logfile later on. Graham P.S. Test it without the log_user line at first when you add the extra code in - otherwise if you have any bugs that cause the carefully choreographed exchange to fail, you won't know where they are. ![]() Posted by pmnf (pmnf), 23 July 2004 Thanks working allreadyThis 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.
Comment by Sathya (published 2011-08-18) Please describe how you did the redirection using a code snippet. [#3969] You can Add a comment or ranking or edit your own comments Average page ranking - 5.0 |
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho | |||||||||||