LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 12-27-2004, 07:53 PM   #1
dmedici
Member
 
Registered: Aug 2003
Posts: 57

Rep: Reputation: 15
Simple Bash Script


Hi all!

Trying to write a very simple Bash script as I learn how to work in Bash...

One line needs me to:

"display any results from the who command about the current user only"

Can someone tell me how to do this?

Many thanks in advance!
 
Old 12-27-2004, 08:12 PM   #2
kilgoretrout
Senior Member
 
Registered: Oct 2003
Posts: 2,292

Rep: Reputation: 138Reputation: 138
$ who | grep [whoami]
 
Old 12-27-2004, 09:10 PM   #3
dmedici
Member
 
Registered: Aug 2003
Posts: 57

Original Poster
Rep: Reputation: 15
Thank you for the very fast reply! It worked when I logged in as root, but then I went to another shell, logged in as TEST, and unfortunately it didn't work there, although typing in WHO as TEST gave me results. Any other possibilities for that line?
 
Old 12-28-2004, 12:16 AM   #4
kilgoretrout
Senior Member
 
Registered: Oct 2003
Posts: 2,292

Rep: Reputation: 138Reputation: 138
Try this:

$ who | grep `whoami`

those are backward single quotes around whoami which is on the same key as the ~ key.
 
Old 12-29-2004, 05:33 PM   #5
dmedici
Member
 
Registered: Aug 2003
Posts: 57

Original Poster
Rep: Reputation: 15
OK, that fix with the tic marks worked! Again, thank you very much! Very fast response!
 
Old 12-29-2004, 07:00 PM   #6
dmedici
Member
 
Registered: Aug 2003
Posts: 57

Original Poster
Rep: Reputation: 15
One more question if I may - I need to do the same thing I did with the WHO command but with the ps command. I tried adding that line below the who | grep `whoami` with ps substituted for who but it didn't take. Any ideas?
 
Old 12-30-2004, 02:46 AM   #7
kilgoretrout
Senior Member
 
Registered: Oct 2003
Posts: 2,292

Rep: Reputation: 138Reputation: 138
Try:

$ ps -ef | grep `whoami`

See man ps. The "ef" switch is necessary to get the user name associated with the process and grep can work from that output.
 
Old 12-30-2004, 04:24 AM   #8
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,276

Rep: Reputation: 170Reputation: 170
how about ?
Code:
ps -u username
billy
 
Old 12-30-2004, 07:55 PM   #9
dmedici
Member
 
Registered: Aug 2003
Posts: 57

Original Poster
Rep: Reputation: 15
Thanks to both of you for the quick replies - both solutions work but in slightly different ways - Kilgore's has slightly more info in the output than billy's, but they are both pretty much what I was looking for. Great job! Really helped me a lot!

D
 
Old 12-31-2004, 03:48 AM   #10
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,276

Rep: Reputation: 170Reputation: 170
if you read the man page for ps
you'll see you can tailor the output
to exactly the fields you want
using an option string.

regards, billy
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Simple bash script lp449 Linux - Networking 3 08-02-2005 04:25 PM
Simple bash script Soulful93 Programming 1 06-04-2005 07:26 PM
Simple Bash Script Help njdownes Programming 2 03-05-2005 07:35 AM
Help with simple bash script - please tw001_tw Linux - Software 5 12-19-2004 09:02 PM
Simple BASH script fio Linux - General 5 01-18-2003 03:26 PM


All times are GMT -5. The time now is 06:31 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration