LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-04-2013, 12:13 PM   #1
sumit.inform
LQ Newbie
 
Registered: Mar 2013
Posts: 19
Blog Entries: 2

Rep: Reputation: Disabled
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
 
Old 03-04-2013, 12:50 PM   #2
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
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.
 
Old 03-04-2013, 06:23 PM   #3
sumit.inform
LQ Newbie
 
Registered: Mar 2013
Posts: 19

Original Poster
Blog Entries: 2

Rep: Reputation: Disabled
Quote:
Originally Posted by shivaa View Post
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
 
Old 03-04-2013, 07:56 PM   #4
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
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\:\:\:\,\"'
 
Old 03-05-2013, 01:16 AM   #5
sumit.inform
LQ Newbie
 
Registered: Mar 2013
Posts: 19

Original Poster
Blog Entries: 2

Rep: Reputation: Disabled
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
 
Old 03-05-2013, 03:25 AM   #6
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
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?
 
Old 03-05-2013, 05:32 PM   #7
sumit.inform
LQ Newbie
 
Registered: Mar 2013
Posts: 19

Original Poster
Blog Entries: 2

Rep: Reputation: Disabled
Yes shiva !!! this works for me....Thanks for the help...it is nice idea ...
 
Old 03-05-2013, 05:52 PM   #8
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Good.

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


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
EXPECT and pattern matching damade Linux - General 2 05-16-2011 10:11 AM
Script Help: How to count a matching pattern in one line? dv502 Programming 3 12-13-2008 01:53 PM
Linux/Unix script for file pattern matching varunnarang Programming 1 08-07-2006 01:14 PM
bash script pattern matching thedude2010 Programming 9 06-02-2006 02:39 AM
Pattern Matching Help in Bash script cmfarley19 Programming 1 04-07-2004 09:22 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:28 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration