Finding a string and displaying the text before?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Finding a string and displaying the text before?
# 1  
Old 05-05-2011
Finding a string and displaying the text before?

Hi folks.

I am trying to script a query of a backup server that will display sessions that are "waiting" for a mount...

So for, i query my system which returns a process # that is waiting...

The output looks like this:
Code:
20,984 Backup Storage Pool Primary Pool T950_TAPE_WIN, Copy Pool T950_VAULT_WIN, Files Backed Up: 561423, Bytes Backed Up: 2,085,547,366,263, Unreadable Files: 0, Unreadable Bytes: 0. Current Physical File (bytes): 5,969,634,749 Waiting for access to input volume 211593L4 (2393 seconds). Current output volume: 210606L4.

I then try to extract the number of seconds it has been waiting. That way, if it is considered too long, i can cancel it...

So far, here is what i have...

Code:
PASSWORD=$(cat /etc/security/tsm/.password)
LOGIN="dsmadmc -se=tsm_server -id=admin -password=${PASSWORD} -dataonly=yes -noconfirm -tab"

PROCESS=`${LOGIN} "q proc"|grep Waiting|awk '{print $1}'`

if [[ $PROCESS = "" ]]
then
        echo "\nThere are no processes waiting.\n"
        else
        echo "\nThese are the processes waiting: " $PROCESS
fi

for i in $PROCESS
do
        WAITING=`${LOGIN} "q proc $PROCESS" | grep seconds`
        echo "\n"$WAITING
        #RESULT=$(echo $WAITING | sed -ne '/volume/ s/\((.*seconds)\)\([[:alnum:]]*\)\(.*\)/:\2/gp')
        #RESULT=$(echo $WAITING | sed 's/.*\(seconds[^ ;]\);*/\1/')
        #RESULT=$(echo $WAITING | sed -n '/Current/,/volume:/p')
        echo "\n"$RESULT
done


The result of "$WAITING" is displayed above. I tried sed using examples and the such but the last one i tried is showing me -after- the word "seconds". What i would like is to export the #### of seconds to my $RESULT. keep in mind that the seconds could be 1, 20, 300, 4335 etc...never the same lenght...

There could be 2 "waiting". One "waiting for access to output volume" and one "waiting for access to input volume"

I'd like to grab either or both if possible...

BTW, i am reading through some "sed" doc...but man...Smilie

Thanks.

Last edited by Franklin52; 05-07-2011 at 09:18 AM.. Reason: Please use code tags
# 2  
Old 05-05-2011
Code:
RESULT=$(echo $WAITING | sed 's/ seconds.*//;s/.*(//' )

?
# 3  
Old 05-06-2011
Quote:
Originally Posted by ctsgnb
Code:
RESULT=$(echo $WAITING | sed 's/ seconds.*//;s/.*(//' )

?

Thanks, that seems to do the trick for now...Smilie Will this capture 2 "waiting" in the same string if it happens?

here is the result with your "sed"


These are the processes waiting: 21,174

21,174 Migration Disk Storage Pool DISKORA_COMMON, Moved Files: 0, Moved Bytes: 0, Unreadable Files: 0, Unreadable Bytes: 0. Current Physical File (bytes): 3,357,495,296 Waiting for access to output volume 211572L4 (36764 seconds).

36764
# 4  
Old 05-06-2011
Quote:
Originally Posted by Stephan
Thanks, that seems to do the trick for now...Smilie Will this capture 2 "waiting" in the same string if it happens?

21,174 Migration Disk Storage Pool DISKORA_COMMON, Moved Files: 0, Moved Bytes: 0, Unreadable Files: 0, Unreadable Bytes: 0. Current Physical File (bytes): 3,357,495,296 Waiting for access to output volume 211572L4 (36764 seconds).

36764
No, it will only display the number which is in the trailing "(36764 seconds)" i.e. 36764

---------- Post updated at 03:52 PM ---------- Previous update was at 03:51 PM ----------

Code:
PROCESSES=$(echo $WAITING | sed 's/ .*//')

Better:
Code:
PROCESSES=${WAITING%% *}


Last edited by ctsgnb; 05-06-2011 at 11:03 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with text modification and displaying

I have a file storing some text and another file storing some numbers I want to display characters other than the specified place of strings one.txt xyz abc 233 skfo 4r443 sfs abc abcd sd fsdf sdfd abc 11 abc 33 abc dsaf two.txt Nt_djd_k='5-6,7-9' Nt_hh_l='3-6,7-8' a=`grep... (4 Replies)
Discussion started by: rahulsk
4 Replies

2. Shell Programming and Scripting

Displaying Formatted Text on Virtual Terminal

Hi, I'm working on a project that requires formatted text to be displayed on the screen plugged into a Linux machine. I want to be able to control this text via a bash script and format it in a particular font and size. Changing the background colour would also be beneficial. Does anyone know... (3 Replies)
Discussion started by: lcoor65
3 Replies

3. Shell Programming and Scripting

Displaying certain text in a msg.

I have a requirement to display a part of an html response that my application gets. The response looks like this: <html><a href='com.aprisma.spectrum.app.sd.client.SDHyperlinkHandler' sdTicketHandle='cr:419900' ocAlarmId='506618ea-f013-102d-02a7-0050569d7aa8'... (3 Replies)
Discussion started by: dlundwall
3 Replies

4. Shell Programming and Scripting

Reformatting single column text file starting new line when finding particular string

Hi, I have a single colum file and I need to reformat the file so that it creates a new line every time it come to an IP address and the following lines are corresponding rows until it comes to the next IP address. I want to turn this 172.xx.xx.xx gwpusprdrp02_pv seinwnprd03... (7 Replies)
Discussion started by: kieranfoley
7 Replies

5. Shell Programming and Scripting

Displaying exponent value as string in PERL script

Hello All, I am currently having an issue displaying a exponent value using perl, I have a perl program which generates an xls file. This xls is populated with values from a database. But for a certain column which I have made explicitely text and also implemented keep_leading_zeroes()... (3 Replies)
Discussion started by: sbasetty
3 Replies

6. Shell Programming and Scripting

Displaying Result to a Text File

Hi; I am scripting in Shell and i want to write output (on screen) to a text file? ... | tee gcsw/output.txt doesnot work? :(:( (6 Replies)
Discussion started by: gc_sw
6 Replies

7. Shell Programming and Scripting

Finding a string in a text file and posting part of the line

What would be the most succinct way of doing this (preferably in 1 line, maybe 2): searching the first 10 characters of every line in a text file for a specific string, and if it was found, print out characters 11-20 of the line on which the string was found. In this case, it's known that there... (13 Replies)
Discussion started by: busdude
13 Replies

8. UNIX for Dummies Questions & Answers

Displaying Text

Hi guys! I am very much new to UNIX...and I was just wondering on how you would display this text format in UNIX with only just one command : Text 1 Text 2 Text 3 Texts are in aligned vertically in such format...Thanks for your help :) (8 Replies)
Discussion started by: Knowledge_Xfer
8 Replies

9. Shell Programming and Scripting

Displaying only First Occurrence of a String

Hi, My requirement is that I should search for a particular string and display the string only once if there is more occurrence of the same string in a file. e.g In the given below log file,the string AMQ5037 comes twice.I want to search for this string and display it only once.grep will... (5 Replies)
Discussion started by: charudpss
5 Replies

10. Shell Programming and Scripting

Displaying text file in browser - perl

I am having issue dispalying text file in browser using perl. Here is my code: #!/usr/bin/perl print "content-type: text/html \n\n"; open (FH , "access.log") || die "Blah $!"; while (<FH>) { print $_ ; } I have correct permissions and everything. The weired thing is when I... (1 Reply)
Discussion started by: Dabheeruz
1 Replies
Login or Register to Ask a Question