LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-06-2014, 05:16 PM   #1
kamran.ayub
Member
 
Registered: Jan 2012
Posts: 72

Rep: Reputation: Disabled
Last command help


Dear All,

I am using last command on centos system to get users logging information. I want to get information of users logging in today date.

Usually last command output is as follows;

kamran pts/0 10.111.11.135 Fri Nov 7 00:34 still logged in
kamran pts/0 10.111.11.51 Fri Oct 31 20:04 - 04:45 (08:41)

Is there a way if last command just show login users of current date and exclude others from output.
Please help

regards,
kamran
 
Old 11-06-2014, 09:43 PM   #2
ember1205
Member
 
Registered: Oct 2014
Posts: 176

Rep: Reputation: 16
You'll want to write a custom script that will determine today's date and then match it against the last output. Not at all hard.
 
Old 11-07-2014, 09:13 AM   #3
kamran.ayub
Member
 
Registered: Jan 2012
Posts: 72

Original Poster
Rep: Reputation: Disabled
Dear ember1205,

I have already tried this option by extracting via bash script. But there is a gap between this in 1 specific situation.

I am asssigning date via
Today_Date=$(date | awk '{print $2," ",$3 }') which results in "Nov 7".

Npw see last command output for this date.

kamran pts/0 10.111.11.135 Fri Nov 7 00:34 - 05:01 (04:27)

In above output Nov & 7 are separated by 2 spaces. When I use below command it does not capture this output.

last | grep "Nov 7" ####i.e in script last | grep $Today_Date

Please help on this.

Regards,
Kamran
 
Old 11-07-2014, 09:46 AM   #4
ember1205
Member
 
Registered: Oct 2014
Posts: 176

Rep: Reputation: 16
Use cut instead...

Today_Date=$(date | cut -b5-10)

This will force it to use the exact information so that "Nov 7" will be formatted properly.
 
Old 11-07-2014, 10:04 AM   #5
kamran.ayub
Member
 
Registered: Jan 2012
Posts: 72

Original Poster
Rep: Reputation: Disabled
Dear ember1205,

Thanks a lot. Problem solved.


Today_Date=$(date | cut -b5-10)

last | grep "$Today_Date"

Putting double quotes around variable results me in exact value which I was expecting.

Thanks ember.

regards,
Kamran
 
Old 11-07-2014, 10:05 AM   #6
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,784

Rep: Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083
Tell date to produce the same format from the start:
Code:
Today_Date=$(date '+%b %e')
Quote:
%b locale's abbreviated month name (e.g., Jan)
%e day of month, space padded; same as %_d
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] timestamp of command history doesn't show time command was executed? UprLftCstr Linux - Newbie 3 04-17-2014 12:31 PM
Command/Script required to send an email alert in case command will not respond rajaniyer123 Linux - General 1 05-19-2012 01:12 PM
Executing shell command from JSP file with command line arg from URL orcusomega Programming 2 01-13-2012 03:38 PM
Bash Command Line Editor, while typing run another command before executing current? gumaheru Linux - General 5 04-13-2010 11:21 AM
LXer: The Linux Command Shell For Beginners: Fear Not The Command Line! LXer Syndicated Linux News 0 12-22-2008 06:30 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration