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:

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...

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...:wall:

Thanks.

RESULT=$(echo $WAITING | sed 's/ seconds.*//;s/.*(//' )

?

Thanks, that seems to do the trick for now...:b: 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

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 ----------

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

Better:

PROCESSES=${WAITING%% *}