Script (320 Views)
Reply
Frequent Advisor
Aggy
Posts: 85
Registered: ‎10-23-2000
Message 1 of 6 (320 Views)
Accepted Solution

Script

I wanted to write a script for our daily checks
Things I wanted was a bdf from 3 servers and syslog.log (YESTERDAYS DATE) with only Critical errors
and any users who were still logged in since yesterday.
Can you please help. the problem I am getting is Yesterdays date

Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 2 of 6 (320 Views)

Re: Script

Hi Aggy:

You can parse the output of this into any pieces you want:

# perl -le 'print scalar localtime(time-86400)'

...or use:

# perl -MPOSIX=strftime -le 'print strftime "%m/%d/%Y",localtime(time-86400)'

The second snippet allows you to chose the format of the output. The directives are the same ones available with the standard Unix 'date' command. See the manpages.

Regards!

...JRF...
Acclaimed Contributor
Dennis Handly
Posts: 25,298
Registered: ‎03-06-2006
Message 3 of 6 (320 Views)

Re: Script

>The problem I am getting is Yesterdays date.

One solution is you put it in a file initially and then the next day you use that. Then you put the current date, to use for the next day.

If you skip a day, you'll end up doing everything back to the last time, that may be good or bad for you.
Honored Contributor
spex
Posts: 1,367
Registered: ‎05-14-1996
Message 4 of 6 (320 Views)

Re: Script

Hello Aggy,

This question seems to come up a lot.

See this thread for details on how to calculate yesterday's date:
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=563529

For small date offsets, you can adjust $TZ:
$ YESTERDAY=$(TZ=$TZ+24 date +%Y%m%d)

For larger offsets, there's A. Clay's Stephenson's "Date Hammer script": caljd.sh.

PCS

Honored Contributor
spex
Posts: 1,367
Registered: ‎05-14-1996
Message 5 of 6 (320 Views)

Re: Script

> Things I wanted was a bdf from 3 servers
> and syslog.log (YESTERDAYS DATE) with only
> Critical errors and any users who were
> still logged in since yesterday.

SLPATH=/var/adm/syslog
YESTERDAY1=$(TZ=$TZ+24 date +"%Y%m%d")
YESTERDAY2=$(TZ=$TZ+24 date +"%b %e")
echo [server1] bdf output:
bdf
echo [server1] critical errors from yesterday's syslog:
grep -i -E 'critical|' ${SLPATH}/syslog.${YESTERDAY}.log
echo [server1] users logged in since yesterday:
who | grep "${YESTERDAY2}"

echo [server2] bdf output:
ssh server2 bdf
... and so on ...

Replace above with other terms of interest from syslog, separated by a pipe ('|').

PCS
Frequent Advisor
Aggy
Posts: 85
Registered: ‎10-23-2000
Message 6 of 6 (320 Views)

Re: Script

Thanks
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.