Apr 1, 2003 #1 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,
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,
Apr 1, 2003 #2 nithink Programmer Nov 7, 2002 92 US You can use tail -1 yourfile hope it helps. Upvote 0 Downvote
Apr 1, 2003 Thread starter #3 dvknn IS-IT--Management Mar 11, 2003 94 US 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 "upsCheck[8]: -s: not found" What is it that I am doing wrong here? thanks, Upvote 0 Downvote
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 "upsCheck[8]: -s: not found" What is it that I am doing wrong here? thanks,
Apr 1, 2003 #4 nithink Programmer Nov 7, 2002 92 US 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. Upvote 0 Downvote
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.
Apr 1, 2003 Thread starter #5 dvknn IS-IT--Management Mar 11, 2003 94 US 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, Upvote 0 Downvote
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,
Apr 2, 2003 #6 nithink Programmer Nov 7, 2002 92 US 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 Upvote 0 Downvote
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
Apr 2, 2003 Thread starter #7 dvknn IS-IT--Management Mar 11, 2003 94 US I got it in another way.. Hey Thanks though..for spending time on this. Upvote 0 Downvote