1844903 Members
2761 Online
110233 Solutions
New Discussion

shell script help

 
kholikt
Super Advisor

shell script help

I am writing a script to abort all omniback backup session that is still running.

This is the output from the omnistat

SessionID Type Status User
===============================================================================
2003/03/11-18 Backup Mount Request root.sys@abc.net
2003/03/11-20 Backup In Progress root.sys@abc.net

This is my script.

#!/usr/bin/sh
OUTPUT=/tmp/abort_backup.rpt
if [ -f $OUTPUT ]
then
rm $OUTPUT
fi
touch $OUTPUT

CONDITION=$(/opt/omni/bin/omnistat | grep "No currently running sessions.")
if [ -n "$CONDITION" ]
then
echo "Not Backup is running"
else

PATTERN_TEXT="backup"
SESSION=`/opt/omni/bin/omnistat | grep -i "$PATTERN_TEXT" | awk '{print $1}'`
DATE=`date`
echo $SESSION > /tmp/abort_list
echo "$SESSION was aborted by script on $DATE"
#/opt/omni/bin/omniabort -ses $SESSION
rm /tmp/abort_list
fi

My problem is sometimes there might be more than 1 sessions running and I want to abort all of them.

When I pipe the $SESSION to a file, all sessions number will be put into one line.

For example in the abort_list file the session number will be look like this.
2003/1/1223-23 2003/2/1223-24

But I would like to have a new line for 2003/2/1223-24 so that I can abort all the session one by one.
abc
4 REPLIES 4
John Poff
Honored Contributor

Re: shell script help

Hi,

You could do a 'for' loop on the contents of your $SESSION variable. Something like this:

PATTERN_TEXT="backup"
SESSION=`/opt/omni/bin/omnistat | grep -i "$PATTERN_TEXT" | awk '{print $1}'`

for SESS in $SESSION;
do
DATE=`date`
echo $SESS > /tmp/abort_list
echo "$SESS was aborted by script on $DATE"
#/opt/omni/bin/omniabort -ses $SESS
rm /tmp/abort_list
fi
done


JP


Michael Tully
Honored Contributor

Re: shell script help

How about building this argument in to get your sessions, then using it to remove them.

for i in `omnistat | sed -n '3,$p' | cut -c1-14`
do
omniabort -session $i
done
Anyone for a Mutiny ?
Michael Steele_2
Honored Contributor

Re: shell script help

Easiest way to two have two or three temporary work files and one final output file. Right now file1 has

2003/1/1223-23 2003/1/1223-23

cat file1 | while read a
do
${echo $a | awk '{ print $2 }'
done > file2

This will give you file1 with :

2003/1/1223-23

...and file2 with

2003/1/1223-23

Now just append them both into file3
cat file1 > file3
cat file2 >> file3

...for the following:

2003/1/1223-23
2003/1/1223-23
Support Fatherhood - Stop Family Law
Robin Wakefield
Honored Contributor

Re: shell script help

Hi,

Just a few thoughts:

You don't need to check a file's existence before removing it, just use the "rm -f filename" syntax to surpress any warning messages.

Your OUTPUT file never seems to be used either.

To save running omnistat more than once, you could wrap it in a loop and case construct:

/opt/omni/bin/omnistat | while read line ; do
case $line
in
"No currently running sessions")
echo "Backup is not running"
;;
*Backup*)
echo $line | awk '{print $1}' | read SESSION
/opt/omni/bin/omniabort -ses $SESSION
echo $SESSION was aborted by script on `date`
;;
esac
done


rgds, Robin