Showing results for 
Search instead for 
Do you mean 

Script

SOLVED
Go to Solution
Frequent Advisor

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

5 REPLIES
Acclaimed Contributor Acclaimed Contributor

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 Acclaimed Contributor

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

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

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
Highlighted
Frequent Advisor

Re: Script

Thanks