| |||||||||||
how to save result of command execution in file in Posted by pgpatel (pgpatel), 16 August 2005 hello,i want to save result of cpommand in one file.... for exe...exp_send "ls -l\r" i want to save result in one file....how can i do this...? any suggestion? thanks Posted by admin (Graham Ellis), 16 August 2005 open the file you want to save it to and write the expect_out(string) variable to it Posted by pgpatel (pgpatel), 17 August 2005 Thanks for reply....I tried it but it showing following error: expect_out(string):no such element in array Here i am sending you my script: spawn telnet 172.25.126.248 expect "login:" exp_send "xyz\r" expect "password:" exp_send "aby\r" exp_send "YBI:;\r" expect -re "(.*)\$" set ret [open got2.txt w] puts $ret $expect_out(string) exit when i am using expect_out(buffer) i am not getting any error but the result saved in file is not what i want... actual result is: YBI:; LOADING PROGRAM VERSION 1.10-0 INTERROGATE IMA GROUP IMA IMA ID MIN / TOT TRL PET GROUP TX RX PHY TTP LINKS TX RX STATE ----- ------- ------- --------- ------- ------------------ 10 4 0 - 4 / 4 0 0 OPERATIONAL LINK RELATIVE PET ID DELAY(MS) NEAR-END STATE FAR-END STATE ----- ---- --------- ------------------ ------------------ 0 0 0 ACTIVE ACTIVE 1 1 1 ACTIVE ACTIVE 2 2 0 ACTIVE ACTIVE 3 3 1 ACTIVE ACTIVE COMMAND EXECUTED result i am getting is : Trying to 172.25.126.248 connected to 172.25.126.248 escape character is '^]'. please reply me as soon as possible.. thanking you... Posted by admin (Graham Ellis), 17 August 2005 on 08/17/05 at 10:32:24, pgpatel wrote:
I always reply as soon as possible .... I don't delay needlessly, you know! ... See the FAQ. However, I'm on the road at the end of a long drive and still out of the office ... Tk books NOT to hand ... so I'm not in a position to post a technical answer tonight Posted by pgpatel (pgpatel), 18 August 2005 hello,I am sorry if you feel bad. but i did not mean that... You already helped me lot in each and every questions. so I am really very sorry... please donot be angry on me because without you who will help me when I have question. thanks.... Posted by admin (Graham Ellis), 18 August 2005 Hey - I did add a smiley. I just have to remind people occasioanlly that this is a no-charge service and I have to reserve the right to answer when I get a chance .... which is likely to be when I get a break from giving paid-for training courses.Posted by pgpatel (pgpatel), 19 August 2005 I tried it but it showing following error: expect_out(string):no such element in array Here i am sending you my script: spawn telnet 172.25.126.248 expect "login:" exp_send "xyz\r" expect "password:" exp_send "aby\r" exp_send "YBI:;\r" expect -re "(.*)\$" set ret [open got2.txt w] puts $ret $expect_out(string) exit when i am using expect_out(buffer) i am not getting any error but the result saved in file is not what i want... actual result is: YBI:; LOADING PROGRAM VERSION 1.10-0 INTERROGATE IMA GROUP IMA IMA ID MIN / TOT TRL PET GROUP TX RX PHY TTP LINKS TX RX STATE ----- ------- ------- --------- ------- ------------------ 10 4 0 - 4 / 4 0 0 OPERATIONAL LINK RELATIVE PET ID DELAY(MS) NEAR-END STATE FAR-END STATE ----- ---- --------- ------------------ ------------------ 0 0 0 ACTIVE ACTIVE 1 1 1 ACTIVE ACTIVE 2 2 0 ACTIVE ACTIVE 3 3 1 ACTIVE ACTIVE COMMAND EXECUTED result i am getting is : Trying to 172.25.126.248 connected to 172.25.126.248 escape character is '^]'. thanking you... Posted by admin (Graham Ellis), 19 August 2005 Ah .. I think I see. The problem now lies in your last expect which you need to program to look for a unique sequence at the end of what you want to capture. As it is, the expect matches at the end of the first line so that's what you get.Try expect "COMMAND EXECUTED" and you should get everything prior to that string in the buffer, thus in the file 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 |