Last command for two days

 
Thread Tools Search this Thread
Operating Systems Linux Red Hat Last command for two days
# 1  
Old 06-19-2013
Last command for two days

Dear Expert,

I'm using RED Hat Linux AS 5, Can you please help me to view the last 2 days logins to server using "last" command.

Thank you,
Fareed.
# 2  
Old 06-19-2013
As there's no option to last that could specify the period you desire, you need to filter the entire output using e.g. awk or grep. As the time format is locale dependent, it's even more difficult to deal with it in general than it is to deal with time differences. If your date command allows for it, try creating a time string for -2days and use that in awk.
This User Gave Thanks to RudiC For This Post:
# 3  
Old 06-19-2013
Thank you very much for the update, I don't know much about with date and awk ..can you please help me to write this script.

Thank you,
Fareed.
# 4  
Old 06-19-2013
Try sth in this direction and juggle around with the parameters to date:
Code:
last | grep "$(LC_ALL=en_US.UTF-8 date -d"-1day"|awk '{print $1,$2,$3}')"
user1  pts/2        :0               Tue Jun 18 09:43 - 17:13  (07:29)    
user1  pts/1        :0               Tue Jun 18 09:43 - 17:13  (07:30)    
user1  pts/0        :0               Tue Jun 18 09:43 - 17:13  (07:30)    
user2  tty6                          Tue Jun 18 08:57 - down   (08:17)    
reboot system boot  3.8.0-25-generic Tue Jun 18 08:57 - 17:14  (08:17)

This User Gave Thanks to RudiC For This Post:
# 5  
Old 06-23-2013
Thank you very much.

I tried the given command its only returning one day login output, but my business requirement is get last three days login report daily via email.

Please help me in this seems we are very close to the target.

Thank once again.

Fareed.
# 6  
Old 06-23-2013
As I said, above is not a perfect answer but a starting point, so play around with the parameters. Which means: experiment yourself to establish the solution that fits your needs. As a last resort, run that command twice or thrice with different date values.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shellscript command to remove files starting with a certain string, and older than 3 days

Hi All, Need help in identifying a shellscript command to remove all files on a server directory, starting with a certain prefix and also older than 3 days. That means files created with that prefix, today or yesterday, shouldn't be removed. Thanks, Dev (3 Replies)
Discussion started by: dev.devil.1983
3 Replies

2. Shell Programming and Scripting

Command not found in shell script - stumped for 4 days

Hello, I like to begin with :wall:.. literally... It has been 4 days and I have no idea how to fix it. Environment - AIX 5.3 I wrote a script to call on ssh to log into another box via PKA to do something else. If I run the script on the terminal, it works 100%. If the SAP customised... (11 Replies)
Discussion started by: plonkagain
11 Replies

3. UNIX for Dummies Questions & Answers

Clarification on '1 days ago' in date command [Found answer, posted within]

I know the topic of getting yesterday's date has been covered ad nauseum, but I just want to be clear on something. I recently started using the command date --date='1 days ago' '+%m/%d/%y' to get yesterday's date and it's been working great. I just want to be certain that it is going to... (1 Reply)
Discussion started by: DeCoTwc
1 Replies

4. Solaris

How to select last 7 days entry from SULOG or LAST command

Hi All, I need to get last 7 days log entries from sulog. The same has to be done for the last command. for ex: when i search for a user "abc" in sulog, i only want to check his entries for the last 1 week. The same has to be done for last command. Can anyone suggest some tips. ... (0 Replies)
Discussion started by: navdeepan
0 Replies

5. AIX

reset the counter days for uptime command

hello, i send the uptime command in the AIX and the days that is UP 14652 days this is around 40 years, today is with the correct date&time, hos can I reset the counter days? somebody can help me? regards (3 Replies)
Discussion started by: timflr
3 Replies

6. Shell Programming and Scripting

Scheduling a command to run every 3 days through cron

Hello, I have to schedule a command to run on every 3 days. Whether the below cron entry will work? 0 3 */3 * * command Please help me out and thanks in advance! (6 Replies)
Discussion started by: Arunprasad
6 Replies

7. UNIX for Dummies Questions & Answers

List out last 2 days files using shell command

Could please help me To view removed files list for last 2 days. (1 Reply)
Discussion started by: santhakumar
1 Replies

8. UNIX for Advanced & Expert Users

Any way to know wt command has been executed from last 2-3 days ?

Is there any way to know, what I have executed on UNIX Command prompt from last 2-3 days ? One more point, some systems are interconnected, is there any way to know, who others have executed what command from last 2-3 days ? I am in big trouble guys. Please help me out ASAP. I am working in... (3 Replies)
Discussion started by: manoja422002
3 Replies

9. HP-UX

Command for delete the directories which are older than 7 days

Hi, My requirement is need to delete the directories (Including files also) which are older than 7 days. So I used below command in one script (script takes 2 input parameters) #$1 - Path of the directory from where we have to delete the directories.# #$2 - Number of days older... (1 Reply)
Discussion started by: sridhar sivakot
1 Replies

10. Shell Programming and Scripting

ls latest 4 days or specify days of files in the directory

Hi, I would like to list latest 2 days, 3 days or 4 days,etc of files in the directory... how? is it using ls? (3 Replies)
Discussion started by: happyv
3 Replies
Login or Register to Ask a Question