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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need help about simple script

Status
Not open for further replies.

scient

IS-IT--Management
Oct 24, 2007
15
US

Hi ,

I need help like to get errpt report everday to my mail....i got most of infor from other guy previous errpr script post ..but I need some changes in this

#!/bin/ksh
# Generate an error report (overview only) for yesterday 0:00h until today 0:00h
# yesterday's date in a format understandable by errpt
YDAY=$(LANG='En_US' perl -e 'print scalar localtime (time() - 86400)'|\
awk 'BEGIN{
mon["Jan"]=1; mon["Feb"]=2; mon["Mar"]=3; mon["Apr"]=4
mon["May"]=5; mon["Jun"]=6; mon["Jul"]=7; mon["Aug"]=8
mon["Sep"]=9; mon["Oct"]=10; mon["Nov"]=11; mon["Dec"]=12
}
{
print mon[$2] $3 "0000" substr($NF,3)
}')
# today's date in same format
TDAY=$(date +'%m%d0000%y')
# errpt call
echo errpt -s ${YDAY} -e ${TDAY}
errpt -s ${YDAY} -e ${TDAY} | mail -s " errors occured at hostname.checkout " XXXXXX@new.net

here this script will give us a errpt which will occur past 24 hours ( I think so ..) am I right ? …but even if no errors
occurs for past 24 hours also we get a blank mail with same subject, ..because this script don’t have a compare
stmt from prev to today date..so my head don’t want that kind so can anyone give me full script with compare stmt included..

thank you in advance..
waiting for reply's

regards,
scient
 
So put the errpt output in a file, mail that file if it is not empty...

Code:
#!/bin/ksh
# Generate an error report (overview only) for yesterday 0:00h until today 0:00h
# yesterday's date in a format understandable by errpt
YDAY=$(LANG='En_US' perl -e 'print scalar localtime (time() - 86400)'|\
awk 'BEGIN{
 mon["Jan"]=1;  mon["Feb"]=2;  mon["Mar"]=3;  mon["Apr"]=4
 mon["May"]=5;  mon["Jun"]=6;  mon["Jul"]=7;  mon["Aug"]=8
 mon["Sep"]=9;  mon["Oct"]=10; mon["Nov"]=11; mon["Dec"]=12
}
{
 print mon[$2] $3 "0000" substr($NF,3)
}')
# today's date in same format
TDAY=$(date +'%m%d0000%y')
# errpt call
errpt -s ${YDAY} -e ${TDAY} > /tmp/errpt.mail.$$
if test -s /tmp/errpt.mail.$$
then
 mail -s " errors occured at hostname.checkout "  XXXXXX@new.net </tmp/errpt.mail.$$
fi
rm -f /tmp/errpt.mail.$$


HTH,

p5wizard
 
thank u so much p5wizard..
u helping lot of ppl..
once again appreciate ur help..

have a good one p5..


 
hai

i implemented the same script have u given above
and the starge thing is i got a mail saying errors occured
the output is correct but the thing is when ever the script is executed i got the following error msg ..do i need to change anything in the script ????

twdvar01/root: /tmp > ./genereport.ksh

perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LC_ALL = (unset),
LC__FASTMSG = "true",
LANG = "En_US"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").

can u guys assist me in this issue

thank you,

Regards,
scient





 
so, change the script to use LANG=C and you should be fine:

Code:
...
YDAY=$(LANG=[red]C[/red] perl -e 'print scalar localtime (time() - 86400)'|\
awk 'BEGIN{
 mon["Jan"]=1;  mon["Feb"]=2;  mon["Mar"]=3;  mon["Apr"]=4
 mon["May"]=5;...

HTH,

p5wizard
 

thank you so much p5wizard

its working with no errors..

i am poor in scripting

regards,
scient
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top