Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 10-17-2013, 12:45 PM   #1
LQ Newbie
Registered: Oct 2009
Posts: 17

Rep: Reputation: 0
Conditional grep and analyzing output


I'm trying to create a simple script to execute a utility, grep the output and then based on the results of the grep, don't output anything (When the LUN is synchronized) or, then grep and output just the relevant text showing just those LUNs that aren't synchronized. I was hoping someone could assist with pointing out what I need to do to update my command to fix.

Here is the original command line and output:

FS1:/home/scripts # symrdf query -g MYDG

Device Group (DG) Name : MYDG
DG's Type : RDF2
DG's Symmetrix ID : 0008675309 (Microcode Version: 5875)
Remote Symmetrix ID : 8675308 (Microcode Version: 5875)
RDF (RA) Group Number : 20 (13)

Target (R2) View Source (R1) View MODES
-------------------------------- ------------------------ ----- ------------
Standard A N A
Logical T R1 Inv R2 Inv K T R1 Inv R2 Inv RDF Pair
Device Dev E Tracks Tracks S Dev E Tracks Tracks MDAE STATE
-------------------------------- -- ------------------------ ----- ------------

DEV001 0A9B WD 0 0 RW 0DCF RW 0 100 C.D. SyncInProg

Total -------- -------- -------- --------
Track(s) 0 0 0 100
MB(s) 0.0 0.0 0.0 6.2

Legend for MODES:

M(ode of Operation) : A = Async, S = Sync, E = Semi-sync, C = Adaptive Copy
D(omino) : X = Enabled, . = Disabled
A(daptive Copy) : D = Disk Mode, W = WP Mode, . = ACp off
(Consistency) E(xempt): X = Enabled, . = Disabled, M = Mixed, - = N/A

I put together the following command line and get the following partial ouptut:

FS1:/home/scripts # symrdf query -g MYDG | grep DEV001 | grep -vq Synchronized && symrdf query -g MYDG | grep -e MYDG -e DEV001

Device Group (DG) Name : MYDG
DEV001 0A9B WD 0 0 RW 0DCF RW 0 0 C.D. Synchronized
DEV001 0ADB RW 0 68 RW 0E1C WD 0 0 C.D. SyncInProg

It outputs the device groups that don't contain the text Synchronized however it also incorrectly outputs lines that do contain the text Synchronized. I'm trying to have it analyze the output and only for those device groups that aren't Synchronized to output the name of the device group along with the status, which in the above example is SyncInProg.

Any help would be greatly appreciated.

Old 10-17-2013, 01:13 PM   #2
Senior Member
Registered: Sep 2009
Location: Orange County, CA
Distribution: Kubuntu x64, Raspbian, CentOS
Posts: 1,850
Blog Entries: 36

Rep: Reputation: 455Reputation: 455Reputation: 455Reputation: 455Reputation: 455
First off, it would be appreciated if you used CODE bbcode markup to encase your code so it is easy to differentiate. An example result should look like the following...

FS1:/home/scripts # symrdf query -g MYDG | grep DEV001 | grep -vq Synchronized && symrdf query -g MYDG | grep -e MYDG -e DEV001
On to your issue when you execute grep -vq you're hiding the output of grep and the "&&" portion of that command is bash logic for running a command after successful exit of the previous command list.

That being said if you extract the command which is giving you output then the following is its own command by itself.

symrdf query -g MYDG | grep -e MYDG -e DEV001
Notice that you're not specifying to omit anything. You're just searching for all lines which contain the string MYDG or DEV001. You should modify that to include something like...

symrdf query -g MYDG | grep -v Synchronized | grep -e MYDG -e DEV001
I also think that your script will always produce undesirable results because you're not cleaning up the output of the previous command (getting rid of the display clutter) showing just what you want. In any case, there's a start for you to be on your way to getting what you want.

Last edited by sag47; 10-17-2013 at 01:15 PM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
analyzing iperf output m4rtin Linux - Networking 3 02-14-2010 07:58 PM
Trying to understand pipes - Can't pipe output from tail -f to grep then grep again lostjohnny Linux - Newbie 15 03-12-2009 11:31 PM
Analyzing /usr/bin/lsattr `echo $PATH | tr ':' ' '` | grep i-- Redshift Linux - Security 2 03-27-2007 09:54 PM
grep output on stdout and grep output to file don't match xnomad Linux - General 3 01-13-2007 05:56 AM
analyzing /proc/net/route output cranium2004 Linux - Networking 2 10-27-2004 08:48 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:33 AM.

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