1

I'm looking for today's and yesterday's hardware error output from errpt in AIX using a shell script. I am getting output but need to grep only date.

e.g

tdy=`date +'%m/%d'`
etdy=`date +'%m%d%%y'`
ydy=`TZ=GMT+24 date +%m%d`
awk '{if ($2 ~ "'^$etdy'" && $4 == "H") print $0}' /tmp/errptoutput.txt > /tmp/errptoutput1.txt
awk '{if ($2 ~ "'^$ydy'" && $4 == "H") print $0}' /tmp/errptoutput.txt >> /tmp/errptoutput1.txt

====cat /tmp/errptoutput.txt
DC32143C   0709073116 P H ent8           PING TO REMOTE HOST FAILED
6169289D   0731073116 P H ent8           PING TO REMOTE HOST FAILED
DC32143C   0801073116 P H ent8           PING TO REMOTE HOST FAILED
========================================================================

So I need to grep only date with year (without hours or minutes) .

Suppose the Hardware date is 0801073116 in errpt.

Output required using above script based on %d%m%y 080116 (only date) not hours and minutes.

What do I need to modify in the above script?

1

I'm sure there's an edge case for using GMT+24 in the date calculation (date math on AIX is hard), but here's a minimal adaptation of your script that generates strings for awk to use for pattern matching today's date and yesterday's date in the mmddhhmmyy format that AIX errpt uses:

tdy=`date +'%m%d'`
tdyy=`date +%y`
ydy=`TZ=GMT+24 date +%m%d`
ydyy=`TZ=GMT+24 date +%y`
today="${tdy}....${tdyy}"
yesterday="${ydy}....${ydyy}"

awk -v today="$today" -v yesterday="$yesterday" \
  '$2 ~ today || $2 ~ yesterday' /tmp/errptoutput.txt > /tmp/errptoutput1.txt

One typo-fix that I noticed was in:

etdy=`date +'%m%d%%y'`

where you had an extra %. I also changed the format of the tdy and etdy date strings so that they only outputted the month and day. My other additions were to gather today's year and yesterday's year, then to assign today and yesterday variables using the month/day values from before, periods for the regular expression to match any character in those positions, then the years.

I see that you're parsing an existing output file, but you may also be interested in the -s and -e flags to errpt, which tell errpt to output only entries in the given date range, for example:

errpt -s 0731000016 -e 0801000016

Would show any errpt entries starting on July 31st of 2016 and ending on August 1st of 2016. To additionally limit the output to Hardware errors, use the d flag:

errpt -s 0731000016 -e 0801000016 -d H

See https://www.ibm.com/support/knowledgecenter/ssw_aix_71/com.ibm.aix.cmds2/errpt.htm or your local man page for more details.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.