grep current user


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers grep current user
# 1  
Old 02-21-2009
grep current user

I'm trying to write a grep command that will be good for the current user of the command but it doesn't work on my server with bash shell. On the server with tcsh I used:
last | grep "$user" and the current user could see how many times they logged on this month. On the other server it doesn't work and I think it's because of the shell. I've tried many variations of this but I'm toasted.Smilie
# 2  
Old 02-21-2009
Try this :

Code:
$ last | grep $USER

# 3  
Old 02-21-2009
ce9888, thanks but that isn't doing it.
While it does work correctly on server #1:
/home/sphillips%last | grep $USER | wc -l
12
It does not work on server #2:
[sphillip~]$ last | grep $USER | wc -l
0
[sphillip~]$ last | grep sphillip | wc -l
58
[sphillip~]$
I'm confused since I've tried several combination with and without quots.
# 4  
Old 02-21-2009
Try to find out what shell variable is containing the username with this command:

Code:
$ env | grep -i user

It should give you a list of shell variables, find which one representing the username and use it.
# 5  
Old 02-21-2009
ce9888, again, thanks.
Its more frustration than anything. I don't know how one is expected to learn this stuff if it works sometimes in some places under certain circumstances. Although it works on server #1 so maybe I should just deep six server #2.
I do appreciate your assistance, keeps me hoping.

[sphillip~]$ env | grep -i user
USER=sphillips7738
[sphillip~]$ last | grep sphillip | wc -l
59
[sphillip~]$ last | grep USER | wc -l
0
[sphillip~]$
# 6  
Old 02-21-2009
Quote:
[sphillip~]$ env | grep -i user
USER=sphillips7738
[sphillip~]$ last | grep sphillip | wc -l
59
[sphillip~]$ last | grep USER | wc -l
0
[sphillip~]$
it should works with :

Code:
[sphillip~]$ last | grep $USER | wc -l

# 7  
Old 02-22-2009
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.
 
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