The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Extract time and host IP from 'who' command? SilversleevesX UNIX for Dummies Questions & Answers 2 05-06-2009 02:05 PM
returned from remote command Frank2004 HP-UX 2 04-30-2008 11:29 AM
script or piece of code where the data returned by a stored procedure you are writing enigma_83 Shell Programming and Scripting 3 04-25-2008 06:44 AM
'who' command pythonman UNIX for Dummies Questions & Answers 3 05-25-2005 11:20 PM
command find returned bash: /usr/bin/find: Argument list too long yacsil Shell Programming and Scripting 1 12-15-2003 06:38 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-08-2009
SilversleevesX SilversleevesX is offline
Registered User
  
 

Join Date: May 2009
Location: Northeast USA
Posts: 48
Question 'who' command -- getting data returned into variables (in bash)

Anyone know how to get the data out of the "who" command?

I'm still in lukewarm pursuit of creating an OS X-like welcome message at the start of any Terminal session, sans having to use either bash login or calling up ssh.

My trials & errors and surfing around have narrowed it down for me somewhat. The 'who' command appears to return a string of the exact kind of data I would like to break up and re-arrange into part of the welcome. I just haven't puzzled out how to 'pull' this returned data, break it up and set variables to the three different 'fields' the command provides (USER, TIME and COMMENT), such that they can be placed in the right positions of a string like

Quote:
Welcome, User.
Last login was on May 1 17:55 from (: 0)
(Of course, in place of "User" would be my own name, as the only user logged in via my startup script.)

Considered responses are welcome.

BZT
  #2 (permalink)  
Old 05-08-2009
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
Use the last command

Code:
last -2 $(whoami) | tail -1 | awk '{print $3,$4,$5}'
Closed Thread

Bookmarks

Tags
bash, data extraction, login, terminal, who command

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:48 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0