'who' command -- getting data returned into variables (in bash)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting 'who' command -- getting data returned into variables (in bash)
# 1  
Old 05-08-2009
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  
Old 05-08-2009
Use the last command

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

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

[BASH] eval command not expanding variables as expected.

Hi Guys, I wrote a collection of bash functions years ago and now need to use them again but I'm getting some error messages when eval tries to expand the variables names. I recollect that I used the shopt command to set one of the options but I can't quite remember the command that I... (8 Replies)
Discussion started by: ASGR
8 Replies

2. Shell Programming and Scripting

[bash] command line substitution with environmental variables

Hi, I'm using an array that contains compiler FLAGS that need to be executed either before ./configure or after the main 'make' command. example of array containing compiler flags. ------------------------------------------------- FLAGS="CFLAGS=\"-arch x86_64 -g -Os -pipe... (7 Replies)
Discussion started by: ASGR
7 Replies

3. Shell Programming and Scripting

Perl Array Variables to be returned to main

Hi All, I can;t seem to print out the array in sequence using the below subroutine. My first element in the array @lotsuffix is suppose to be $lotsuffix as defined in the subroutine, but when the array variable is being pass on the main program, my first element actually becomes $lotsuffix ! ... (4 Replies)
Discussion started by: Raynon
4 Replies

4. Shell Programming and Scripting

number of lines returned from a grep command

hi all, from a shell (ksh) script, i am doing a 'grep'. how do i find out the number of lines returned from that 'grep' command ?? thanks in advance. (4 Replies)
Discussion started by: cesarNZ
4 Replies

5. Shell Programming and Scripting

How to find out command has returned any value?

Hi Pals I am using this command in my script to find out warnings using fgrep where $log is the log file name, $date is the date to be searching and warnings.list contains list of matching words. grep "WARNING" $log|grep "$date"|fgrep -vf warnings.list I want to perform another action... (1 Reply)
Discussion started by: johnl
1 Replies

6. HP-UX

returned from remote command

Hi, there, I want to excute the remote command shell via "remsh", are there any simple or best way to get the result of remote shell from local ? thanks. (2 Replies)
Discussion started by: Frank2004
2 Replies

7. Shell Programming and Scripting

script or piece of code where the data returned by a stored procedure you are writing

hi fndz. Can you please help me with the code if I call a stored procedure from my shell script and stored procedure returns a cursor, cursor output should be saved to a file (3 Replies)
Discussion started by: enigma_83
3 Replies

8. UNIX for Dummies Questions & Answers

Problem with files returned using Find command

When I enter the command below grep appears to be returning a file it shouldn't. find . -name "*.*" -exec grep "testing" {} /dev/null \; :tps3Mailfile ./SSI.ksh: # create TECHOUT dummy for test for testing purposes ./ftprimi1.ksh:# before running job in prod... change FTP to go to rimi... (3 Replies)
Discussion started by: dfb500
3 Replies

9. Shell Programming and Scripting

command find returned bash: /usr/bin/find: Argument list too long

Hello, I create a file touch 1201093003 fichcomp and inside a repertory (which hava a lot of files) I want to list all files created before this file : find *.* \! -maxdepth 1 - newer fichcomp but this command returned bash: /usr/bin/find: Argument list too long but i make a filter all... (1 Reply)
Discussion started by: yacsil
1 Replies

10. UNIX for Advanced & Expert Users

w/who command returned zero users

Hi ppl, We are using Sun OS and recently, encountered this strange problem. When issuing the "w" or "who" command, the system produce no listing. See screen shot below. ----------------------- $ w 2:56pm up 2 day(s), 21:10, 0 users, load average: 1.03, 0.75, 0.69 User tty ... (6 Replies)
Discussion started by: sinyem
6 Replies
Login or Register to Ask a Question