Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

who /var/adm/wtmp within 7 days 1

Status
Not open for further replies.

gatetec

MIS
Mar 22, 2007
420
US
I need to get the lists of who from /var/adm/wtmp within 7 days from "now". How do you do that?

who /var/adm/wtmp ??? -mtime +7

thx much
 
Ok first to take the simple concept as greping the output of who /var/adm/wtmp command for a date in this formate "Month date_of_month"

for example,

who /var/adm/wtmp | grep "May 17"

To list all users logged in on May 17 (assuming that its today's date which can be derived from the date command)

To get the Month: month=$(date +"%b")
To get the date of the month: today=$(date +"%d")

Now the trick is to go back one day at a time (up to 7 days ago) which you need to subtract today's dates from yesterday and the day before and so on. To do this i advice you to go throught this link which describe how to subtract dates.


I wish if i can test this but i don't have a machine next to me for now!

Regards,
Khalid
 
I have tried all possible ways, but still not sure.

i.e.

# `TZ=y200 date +%h""%d`
>> May09

# `TZ=y200 date +%h" "%d`
>> May

I need to get "May 09" with a space.

Any ideas?

thx much
 
I just did it!

Code:
# date +%h" "%d
May 21

and if you want to store this into a variable you can do this:

Code:
# mytime=$(date +%h" "%d)
# echo $mytime
May 21

Regards,
Khalid
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top