- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Script to get data from wtmp
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2007 10:09 AM
05-02-2007 10:09 AM
On the first of every month (via cron) append a report called ‘secure’ with anyone who logged in etc via console or accessed a root command the previous month. I need to also make sure it’s the current year.
I know how to get the year from wtmp you need to convert it:
/usr/sbin/acct/fwtmp /var/adm/tmp2
cat /var/adm/tmp2 root console | egrep '$previous_month|$current year' | egrep ‘root|console’ >> /var/adm/secure
How do I sent the variables for previous_month and current_year?
This should be easy..
I tried current_year=’date “+Y%”’ but it doesn’t work and I don't have a clue on pervious_month.
…HELP!
Thanks!!!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2007 12:45 PM
05-02-2007 12:45 PM
Re: Script to get data from wtmp
typeset -i10 MO=1
typeset -i10 YR=0
date '+%m %Y' | read MO YR
((MO -= 1))
if [[ ${MO} -lt 1 ]]
then
MO=1
((YR -= 1))
fi
echo "Previous Month: ${MO} Year: ${YR}"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2007 12:46 PM
05-02-2007 12:46 PM
Re: Script to get data from wtmp
# current_year=`date +%Y`
For the previous month name, constuct an array of names and index by the value of the current month less one. Wrap-around if the current month is the last of a year.
# previous_month=`perl -le '@name=qw{Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec c};$m=(localtime(time))[4];print $name[$m>0?$m-1:11]'`
...I chose to use Perl since I can derive the current month (zero-relative) and perform the lookup in one easy swoop.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2007 01:26 PM
05-02-2007 01:26 PM
Re: Script to get data from wtmp
Thanks but it comes back with:
Previous Month: 4 Year: 2007
Which yes 4 is previous to 5.
What Iâ m really looking for in the variable is the three char month i.e May, Aug since thatâ s what I get out of wtmp converted to asci.
So close!
James--The date works perfect..
Can you do the previous month in a shell (not perl) in the three char format.
Thanks again..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2007 02:03 PM
05-02-2007 02:03 PM
Re: Script to get data from wtmp
> Can you do the previous month in a shell (not perl) in the three char format.
OK, but Perl is more fun :-)
# cat ./lastmonth
#!/usr/bin/sh
typeset -i M=`date +%m`
set -A name Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
(( M -= 2 ))
if [ ${M} -lt 0 ]; then
M=11
fi
echo ${name[M]}
exit 0
...simply run:
# ./lastmonth
Apr
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2007 02:17 PM
05-02-2007 02:17 PM
Re: Script to get data from wtmp
previous_month=$(expr`date +%m` -1)
sh: expr05: not found.
/ # previous_month=`date +%m -1`
/ # echo $previous_month
05
Sigh!
It now occurs to me that I'll run into a problem when I try and get the data Jan for Dec data. I'll have previous month..but then I'll need previous year.
Double Sigh!!
Thanks again for any help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2007 02:27 PM
05-02-2007 02:27 PM
Re: Script to get data from wtmp
Well, one way to compute the previous year is:
# typeset -i Y=`date +%Y`;(( Y -= 1 ));echo $Y
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2007 02:33 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2007 02:36 PM
05-02-2007 02:36 PM
Re: Script to get data from wtmp
Perfect!!!!