Operating System - HP-UX
1753797 Members
6838 Online
108799 Solutions
New Discussion юеВ

Re: Last command does not show year in HP-UX

 
Bharat Walunj
Occasional Contributor

Last command does not show year in HP-UX

Hi,

Please let me know if their is any script to generate the year with last command.
$ last oracle|more
oracle pts/1 Mon Aug 27 15:49 - 17:55 (02:06)


For solaris we have as

last | nawk 'BEGIN {y='`date +%Y`'}$5 == "Dec" && last != "Dec" { y-- }{ print y,$0 ; last = $5 }' |more

But nawk does not work in HP.
7 REPLIES 7
Asif Sharif
Honored Contributor

Re: Last command does not show year in HP-UX

Hi Walunj,

Please read the thread below.
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1143386

Regards,
Asif Sharif
Regards,
Asif Sharif
whiteknight
Honored Contributor

Re: Last command does not show year in HP-UX

Hi Bharat,

last command will not display year. But you can use fwtmp to extract out the year.

To read the contents of the wtmp file, cat the file to fwtmp, as follows:

#cat /var/adm/wtmp | /usr/sbin/acct/fwtmp

WK

please assign points
Problem never ends, you must know how to fix it
Steven E. Protter
Exalted Contributor

Re: Last command does not show year in HP-UX

Shalom,

You let users remain logged on the system constantly from year to year?

As the thread shows, the information certainly does exist, however the reason HP didn't include it may be the basic assumption that everybody knows what year it is.

Even 24/7 systems should be brought down twice a year for critical bi-annual and security patches, making the need to display the year, somewhat superflous?

Good Luck,

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Suraj Kumar Sankari
Occasional Advisor

Re: Last command does not show year in HP-UX

Hi In HP nawk is not working you have to try with awk only
Dennis Handly
Acclaimed Contributor

Re: Last command does not show year in HP-UX

>For Solaris we have as ...

Ah, I didn't look at the script. I thought of writing something like this for the other thread but using fwtmp seemed better.

Your awk script has several flaws. You need to look at $4 and sometimes $5 (if you rebooted in Dec). Also `` doesn't work within '', so you need to use -v:
last | awk -v y=$(date +%Y) '
{
if ($2 == "system" && $3 == "boot") month = $5
else month = $4
if (month == "Dec" && last != "Dec") y--
print y,$0
last = month
}'
Peter Nikitka
Honored Contributor

Re: Last command does not show year in HP-UX

Hi,

besides the correct approach to use 'fwtmp', I see no problem in this awk-statement regarding backticks:
awk 'BEGIN {y='`date +%Y`'} ...'

Having spliced in the `..` into two parts of single quoted strings AND `date +%Y` not producing any spaces in output, the finally string the shell leaves as commands for the awk is only one argument and so perfectly OK.

mfG Peter

The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
Dennis Handly
Acclaimed Contributor

Re: Last command does not show year in HP-UX

>Peter: Having spliced in the `..` into two parts of single quoted strings AND `date +%Y` not producing any spaces in output

Ah, you are correct but nobody in their right mind should use that. The whole awk script should be single quoted, not pieced together like Humpty-Dumpty. Also, this wouldn't work for awk -f.

Here is another thread about awk -v:
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1131538
And here is where I explain your trick:
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1105084
Bill:
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1049976

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=810890
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=324808