LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Pattern Matching in expect script (https://www.linuxquestions.org/questions/linux-software-2/pattern-matching-in-expect-script-4175452663/)

sumit.inform 03-04-2013 12:13 PM

Pattern Matching in expect script
 
Hi,

I made a Expect - script to automate the process in communication Boxes. Login : User ID / Pwd and entering into the box is done but I stuck with the problem if once the pattern match then only next command will process.

As an instance :
below command will run in automatic manner after login into the box
rtrv-crs-sts1::4-2-2:xyz;
and then provide the output on prompt like below
IP sk5829
SBTNVTDPFOMG 13-03-04 18:07:55
M SK5829 COMPLD
"4-2-2,1-17:::,"
"4-2-2,2-17:::,"
I need to catch here 4-2-2,1-17:,4-2-2,2-17:in this manner so that in next command I can use them.
Please suggest me how to catch both output.

Thanks in advance.


Thanks

shivaa 03-04-2013 12:50 PM

Do you want something like this?
Code:

~$ echo ""4-2-2,1-17:::," | awk  'BEGIN{FS=":"}; {print $1.FS}'
OR
~$ <input> | awk  'BEGIN{FS=":"}; {print $1.FS}'

In order to use this value in next cmd, store it's output in some variable, as:
Code:

VAL=$(<input> | awk  'BEGIN{FS=":"}; {print $1.FS}')
You can then use this VAL variable in next command as $VAL.

Hope this will help, if I understood your requirement properly.

sumit.inform 03-04-2013 06:23 PM

Quote:

Originally Posted by shivaa (Post 4904513)
Do you want something like this?
Code:

~$ echo ""4-2-2,1-17:::," | awk  'BEGIN{FS=":"}; {print $1.FS}'
OR
~$ <input> | awk  'BEGIN{FS=":"}; {print $1.FS}'

In order to use this value in next cmd, store it's output in some variable, as:
Code:

VAL=$(<input> | awk  'BEGIN{FS=":"}; {print $1.FS}')
You can then use this VAL variable in next command as $VAL.

Hope this will help, if I understood your requirement properly.

Thanks Shiva for Such a nice suggestion. In some term I can use this like If I will dump all my input in a file the grep the
Pattern 4-2-2,1-17:::, and then use your suggested command.

But In my problem I am into the live BOX and it is throughing out the output on shell
rtrv-crs-sts1::4-2-2:xyz;
and then provide the output on prompt like below
IP sk5829
SBTNVTDPFOMG 13-03-04 18:07:55
M SK5829 COMPLD
"4-2-2,1-17:::,"
"4-2-2,2-17:::,"
--------------
---------------
--more output on prompt.
here in live action i need to catch the pattern "4-2-2,1-17:::,"and take into varaible.

Thanks

shivaa 03-04-2013 07:56 PM

To be honest, your example isn't at all clear & leads to more confusion.

Which command you're running and how are you providing input to that command? Why you want to catch 4-2-2,1-17:::," and where this value will be used. Please make it little more clear. And can't you do like this?
Code:

~# <input> | grep '4\-2\-2\,1\-17\:\:\:\,\"'

sumit.inform 03-05-2013 01:16 AM

Hi Shiva,

Let me more clear on my point.
This script is to automate the Communication Box process. Here I need to login into the box from remote location with telnet via IP address.
There are some certain set of commands which are needed to be through into the box one by one as per process.So in between this process when I am retrieving the logicals with automation by using command rtrv-crs-sts1::4-2-2:xyz; where <4-2-2> is provided input from comand line only.
it provides the output
IP sk5829
SBTNVTDPFOMG 13-03-04 18:07:55
M SK5829 COMPLD
"4-2-2,1-17:::,"
"4-2-2,2-17:::,"
immidiately in second line i need to handle the output and use this for another command.

I hope this may clear little bit. Hope for fruitfull result.

Thanks

shivaa 03-05-2013 03:25 AM

You can save/redirect this output to some file, as:
Code:

rtrv-crs-sts1::4-2-2:xyz; > /tmp/outfile.txt
You can then use this file to provide input for next command.

But what sort of this box is and which OS?

sumit.inform 03-05-2013 05:32 PM

Yes shiva !!! this works for me....Thanks for the help...it is nice idea ...

shivaa 03-05-2013 05:52 PM

Good. :)

BTW, you can Mark the thread as Solved, if you think it has so (option is under Thread Tools on top menu).


All times are GMT -5. The time now is 11:57 PM.