grep current user


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers grep current user
# 8  
Old 02-25-2009
Quote:
Originally Posted by steveu
No, I tried that too, my second post. It works just fine on the FreeBSD box, I don't know what the issue is but thanks for your efforts ce9888.
Well, if all else has failed, post the output of the "env" command to the list.
# 9  
Old 02-25-2009
It sounds like you're on the right path. I'd suggest just breaking it down. First, find out who $USER is on the box that seems not to work correctly:

Code:
echo $USER

Let's say the response is 'bob'. Next, rather than using $USER, instead grep for 'bob':
Code:
> last | grep bob
bob        console                   Mon Feb 23 20:11 - 20:21  (00:10)
bob        ttyv0                     Mon Feb 23 19:20 - shutdown  (00:00)
bob        ttyv0                     Mon Feb 23 17:28 - 19:18  (01:50)

Of course, you might not get anything, so you might want to check "last" manually and see if bob's on the list. If not, and you're logged in as bob, last would seem to be broken in some way. If so, grep is broken, which seems pretty unlikely. If grepping for bob works, but grepping for $USER doesn't, then the use of env variables is failing. Try one of these:

Code:
last | grep `echo $USER`

or

Code:
last | grep `whoami`

# 10  
Old 02-25-2009
ShawnMilo and treesloth, those suggestions all worked. I thank you very much for your time on this issue.
# 11  
Old 02-26-2009
How about going without the grep? Is there a specific reason it's needed?

Code:
[rx4521 ~]$ last
rx4521   tty7         :0               Thu Feb 26 11:00   still logged in
rick     tty2                          Thu Feb 26 10:54    gone - no logout
rick     tty2                          Thu Feb 26 10:53 - 10:54  (00:00)
rx4521   tty7         :0               Wed Feb 18 10:57 - 11:00 (8+00:02)
rx4521   tty7         :0               Wed Feb 18 10:55 - 10:56  (00:01)

wtmp begins Wed Feb 18 00:34:49 2009
[rx4521 ~]$ last $USER
rx4521   tty7         :0               Thu Feb 26 11:00   still logged in
rx4521   tty7         :0               Wed Feb 18 10:57 - 11:00 (8+00:02)
rx4521   tty7         :0               Wed Feb 18 10:55 - 10:56  (00:01)

wtmp begins Wed Feb 18 00:34:49 2009
[rx4521 ~]$

# 12  
Old 02-27-2009
rmoncello, without grep works fine too. I think it turned out to be a server issue because all the commands worked on the other servers. Thanks for the reply. Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Unable to access current user's mailbox.

In any non-root account, whenever I enter mail, it gives me: /var/spool/mail/root: Permission deniedI am not logged in as root, why is mail accessing root's mailbox ? I am unable to enter the currently logged in user's mailbox. Any help is appreciated :) (2 Replies)
Discussion started by: Hijanoqu
2 Replies

2. Shell Programming and Scripting

Grep a pattern in current date logs

Hello, I need to write one script which should search particular pattern like ABCD in log file name hello.txt only in current date logs. in current directory i have so many past date logs but grep should be applied on current date logs. on daily basis current date logs are in number 30 and... (2 Replies)
Discussion started by: ajju
2 Replies

3. Shell Programming and Scripting

Ps - list where UID is numeric or name and for current user

Hi, 'ps -ef' returns output of the following format UID PID PPID C STIME TTY TIME CMD root 17573 1 0 Sep12 tty6 00:00:00 /sbin/mingetty tty6 hpsmh 18150 14864 0 Sep12 ? 00:00:00 /opt/hp/hpsmh/sbin/hpsmhd -DSSL -f /opt/hp/hpsmh/conf/smhpd.conf root ... (3 Replies)
Discussion started by: ysrini
3 Replies

4. Shell Programming and Scripting

How to Login as another user through Shell script from current user[Not Root]

Hi Every body, I would need a shell script program to login as different user and perform some copy commands in the script. example: Supppose ora_toms is the active user ora_toms should be able to run a script where user: ftptomsp pass: XXX should login through and run the commands ... (9 Replies)
Discussion started by: ujjwal27
9 Replies

5. Shell Programming and Scripting

current logged in user

Hey guys I need a script that reads a login name and verifies if that user is currently logged in i have found few commands like "who" and "users" but i wonder how can i verify it that login name is logged in or not? (3 Replies)
Discussion started by: nishrestha
3 Replies

6. UNIX for Dummies Questions & Answers

Search current folder and subfolders with grep

Hello, Neither ‘Grep -r' nor ‘grep -R' is working in my environment. (Searching for a text pattern in the files) Any suggestions... Using SunOS 5.9 Thanks, Trinanjan. (1 Reply)
Discussion started by: bhanja_trinanja
1 Replies

7. Shell Programming and Scripting

Displaying current user process

When I typed in ps -a I get this: PID TTY TIME CMD 31799 pts/3 00:00:00 vim 31866 pts/3 00:00:00 vim And to check who is currently logged in, I type who Felix Whoals Tada Whoals Lala Whoals How can I get the user process for all current users who logged in?? I think I need to combine... (14 Replies)
Discussion started by: felixwhoals
14 Replies

8. Shell Programming and Scripting

To look for occurrences of the current user

I have crated a file xx wth env redirected into it 5 times n couldnot proceed further n next we have to create a script that takes 1 argument being a file, in this instance we use the newly created file above xx(xx file contains the env redirected into it 5 times) read the inputted file, in... (1 Reply)
Discussion started by: bobby36
1 Replies

9. UNIX for Dummies Questions & Answers

using grep to find a value in current dir and sub dirs?

Hey guys, I would like to find all files which contain "client1.dat". I would like to search from the current directory and all subs and print out all the files that have this. Any help would be greatly appreciated. Thanks much. (10 Replies)
Discussion started by: ecupirate1998
10 Replies

10. Programming

Who is the current user

How could I get the username and password of user, who started this programm? (6 Replies)
Discussion started by: szzz
6 Replies
Login or Register to Ask a Question