Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Monitoring Script

Status
Not open for further replies.

dvknn

IS-IT--Management
Mar 11, 2003
94
US
Hi,

How can I grep for the last line in a file?

the last line in my file will (always be) be

'Server is DOWN'.

I need to grep for this, and if the last line is ... 'Server is DOWN', then I need to send a mail.

How can I do that?

Thanks,
 
Thanks.

My script is like this:

#!/usr/bin/ksh
grep 'UserProfileServer is DOWN' appcheck.log > appcheck.err

if (-s appcheck.err) then
MSG='Server is DOWN'
mail abc@yahoo.com < $MSG
fi

I am getting an error &quot;upsCheck[8]: -s: not found&quot;

What is it that I am doing wrong here?

thanks,
 
I believe you are using korn shell.

The 'if' syntax for korn shell,

if [ -s appcheck.err ]
then
MSG='Server is DOWN'
mail abc@yahoo.com < $MSG
fi

Hope it helps.
 
OK...that's not working..

I have a file which has 'Server is DOWN' line in it. I have to grep for this line and then sned an email.

How can I do that?

Thanks,
 
There may be some other simple way.. but you can try this too if its OK for you..

#!/bin/sh

check=`grep -i server ./yourfile | tail -1`

if [ check -eq 'Server is DOWN' ]
then
mail dvknn < letter
fi
 
I got it in another way..

Hey Thanks though..for spending time on this.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top