1834814 Members
2599 Online
110070 Solutions
New Discussion

script question here

 
Ragni Singh
Super Advisor

script question here

Hello guys. Help me with this script here. What I should be able to do in the end is, if my make recovery is sucessful, I want my table to display a green color and when it ends uncessful, it needs to show a red color. What is wrong with my script.

# Get the start time

ssh $i "tail -10 /var/opt/ignite/logs/makrec.log1 2> /dev/null | grep 'Started'" > $TMP_PAGE2

echo "
" >> $TMP_PAGE2
echo $END >> $TMP_PAGE2

# Get the end time - will also use later for COLOR selection

END=$(ssh $i "tail -2 /var/opt/ignite/logs/makrec.log1 2> /dev/null |
grep '^Ended'")


echo "
" >> $TMP_PAGE2
echo "" >> $TMP_PAGE2

# Get the failure code and set the color

FAIL_CODE=$(ssh $i "tail -1 /var/opt/ignite/logs/makrec.log1 2> /dev/null | grep 'Ended' 'makrec.log1' | tail -1")

case $FAIL_CODE in

"Completed" )
COLOR="GREEN"
;;

"Ended" )
COLOR="RED"
;;

* )
COLOR="RED"
;;


esac

# Also set the COLOR based on $END

[ $(echo $END | grep -c Ended) -eq 1 ] && COLOR="GREEN"

# Build the first column - This is where we set the color

echo "" > $TMP_PAGE1

echo "" >> $TMP_PAGE1
echo "$i
" >> $TMP_PAGE1
echo "" >> $TMP_PAGE1
echo "
" >> $TMP_PAGE1

# Pull it together

cat $TMP_PAGE1 $TMP_PAGE2 >> $PAGE

done

# end the table

echo "" >> $PAGE
echo "" >> $PAGE
6 REPLIES 6
Sridhar Bhaskarla
Honored Contributor

Re: script question here

Sanman,

Check the line

FAIL_CODE=$(ssh $i "tail -1 /var/opt/ignite/logs/makrec.log1 2> /dev/null | grep 'Ended' 'makrec.log1' | tail -1")

Also, 'makrec.log1' in the above should give you an error that makrec.log1 not found.

tail -1 gives you ****** . You may need to make it tail -2.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Ragni Singh
Super Advisor

Re: script question here

Thanks but that didn't help. What I want the script to do is if it was sucessful, I would get a green columm and if it was uncessful, I would get a red columm. Hope this helps.
Sridhar Bhaskarla
Honored Contributor

Re: script question here

Sanman,

Try this.

remsh $i "tail -10 /var/opt/ignite/logs/makrec.log1 2> /dev/null | grep 'Started
'" > $TMP_PAGE2

echo "
" >> $TMP_PAGE2
echo $END >> $TMP_PAGE2

# Get the end time - will also use later for COLOR selection

LINE=`remsh $i tail -2 /var/opt/ignite/logs/makrec.log1|head -1`
DATE=`echo $LINE |awk '{FS="-";print $2}'`
FAIL_CODE=`echo $LINE |awk '{FS="-";print $1}'`

case $FAIL_CODE in

"Completed " )
COLOR="GREEN"
;;

"Ended " )
COLOR="RED"
;;

* )
COLOR="RED"
;;

esac


# Build the first column - This is where we set the color

echo "" > $TMP_PAGE1

echo "" >> $TMP_PAGE1
echo "$i
" >> $TMP_PAGE1
echo "" >> $TMP_PAGE1
echo "
" >> $TMP_PAGE1

# Pull it together

cat $TMP_PAGE1 $TMP_PAGE2 >> $PAGE

# end the table

echo "" >> $PAGE
echo "" >> $PAGE

rm $TMP_PAGE1 $TMP_PAGE2





You may be disappointed if you fail, but you are doomed if you don't try
Bill Hassell
Honored Contributor

Re: script question here

The test for FAIL_CODE in the case statement is asking for an exact match for the words Ended and Completed. If the line contains any other text (and grep will return everything on the line), the test will drop to *) and make the color RED.

It would be better to simply ask grep how many matches it found:

... grep -c Completed ...

if [ $FAIL_CODE -eq 0 ]
then
COLOR=RED
else
COLOR=GREEN
fi


Bill Hassell, sysadmin
Sridhar Bhaskarla
Honored Contributor

Re: script question here

Oops.. You need to replace "remsh" with "ssh".
Also, I assigned DATE but not used it anywhere. You can use it somewhere in your table.

Also, I didn't understand why you were grepping "Started" in the first sentence. So, I included it as it is..

But if your intention is to find the Starting time, there would be multiple such entries. You can do it like this.

ssh $i cat /var/opt/ignite/logs/makerec.log1|grep 'Started' |tail -1 > $TMP_PAGE2

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Ragni Singh
Super Advisor

Re: script question here

Sorry guys, didn't mean to ignore anyone.