Simpler Navigation for Servers and Operating Systems
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
cancel
Showing results for 
Search instead for 
Did you mean: 

script help

Ragni Singh
Super Advisor

script help

This is my script and its not doing what I need it to do. My script needs to get the start and end time of the make recovery. The if my make recovery is sucessful, it needs to display a green color and if its not sucessful, it needs to display a red color. Any help is greatly appreciated.
#!/usr/bin/ksh
##################################################################

# Declare variables
PATH=/usr/bin:/usr/local/bin
SERVERS="/opt/data/all-servers"
PAGE="/opt/apache/htdocs/backups/test.html"
TMP_PAGE1="/tmp/list1.html"
TMP_PAGE2="/tmp/list2.html"
DATE=$(date)
COLOR=""
FAIL_CODE=""
END=""

# Make sure we start clean
/usr/bin/rm -f $TMP_PAGE1 $TMP_PAGE2

# Start the page

cat <<-EOF > $PAGE


<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

Make Recovery Completions


Last updated: $DATE



NOTES:




This page is currently being built.



EOF

# Start the table

cat <<-EOF >> $PAGE





EOF

# Get the data

for i in `cat $SERVERS` xxxxx xxxxxxx
do

# Get the start time

ssh $i "tail -2 /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 '^Completed'")


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 -2")

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


4 REPLIES
linuxfan
Honored Contributor

Re: script help

Hi,

Few errors i found were,

1. In the start of the page, you are using a here-to doc, and using cat << -EOF but you are ending it with EOF, you might want to be consistent.

2. Same issue with start of table. Mismatch -EOF and EOF.

3. Getting the start time, you are doing a tail -2 and looking for start time, but it may not be available. you are better of doing
ssh $i "grep '^Started' /var/opt/ignite/logs/makrec.log1 2> /dev/null |tail -1" > $TMP_PAGE2

4. Same issue with FAIL_CODE, you want to grep for Ended and then look at the last entry.

One way to check is to print the values of the variables. echo "END is $END" etc.

-HTH
Ramesh
They think they know but don't. At least I know I don't know - Socrates
harry d brown jr
Honored Contributor

Re: script help


Also, what is the "grep 'Ended' 'makrec.log1' " supposed to do? "grep" will return with an error that it can't find "makrec.log1", unless you are in the /car/opt/ignite/logs directory.

FAIL_CODE=$(ssh $i "tail -1 /var/opt/ignite/logs/makrec.log1 2> /dev/null | grep 'Ended' 'makrec.log1' | tail -2")
Live Free or Die
Sridhar Bhaskarla
Honored Contributor

Re: script help

Sanman,


You already posted this question before. Check this thread out.

http://forums.itrc.hp.com/cm/QuestionAnswer/1,11866,0x21eac6af36b7d5118ff10090279cd0f9,00.html

The solution works. I tried it out.

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

Re: script help

Hey guys, thanks for all the help with my script but I can't seem to get this work the way I want it to. I'm again sending you my script to look at. The way its set up is it first greps for the start time. Tehn it greps for the time it was completed. Then on certail machine, my make recovery doesn't work and if I did a tail on the log, it says, 'Ended Unsucessfully". So my FAIL_CODE needs to look for this meesage and my if statement says, if the job completed, display a green columm, and if the job is unsucessful, then display my columm red. Hope this helps and thnaks for all your time and help.

#!/usr/bin/ksh
##################################################################
# Declare variables
PATH=/usr/bin:/usr/local/bin
SERVERS="/opt/data/all-servers"
PAGE="/opt/apache/htdocs/backups/test.html"
TMP_PAGE1="/tmp/list1.html"
TMP_PAGE2="/tmp/list2.html"
DATE=$(date)
COLOR=""
FAIL_CODE=""
END=""

# Make sure we start clean
/usr/bin/rm -f $TMP_PAGE1 $TMP_PAGE2

# Start the page

cat <<-EOF > $PAGE


<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

Make Recovery Completions


Last updated: $DATE



NOTES:




TEST



TEST



TEST




EOF

# Start the table

cat <<-EOF >> $PAGE





EOF

# Get the data

for i in `cat $SERVERS` xxxxx xxxxxx
do

# Get the start time

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

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

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

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

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

# Get the failure code and set the color

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


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

# 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