LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-06-2004, 04:13 AM   #1
Cruger
LQ Newbie
 
Registered: Mar 2004
Posts: 14

Rep: Reputation: 0
Trying to see who is logged in


Trying to write a script that tells me who's logged in...
I think I've missed something obvious...

script as it is now:

for i in $*
do
whoami
done
echo "Username is not logged in"
 
Old 03-06-2004, 04:33 AM   #2
HappyTux
Senior Member
 
Registered: Mar 2003
Location: Nova Scotia, Canada
Distribution: Debian AMD64
Posts: 3,514

Rep: Reputation: 69
The "who" command possibly.
 
Old 03-06-2004, 05:59 AM   #3
snacky
Member
 
Registered: Feb 2004
Distribution: Debian
Posts: 286

Rep: Reputation: 30
Just use "w"

whoami doesn't work like that, it just tells you who is the current user executing the "whoami" command!

You might like this:
Code:
w |awk -F\  '{print $1 }' |sort |uniq
 
Old 03-06-2004, 06:21 AM   #4
Cruger
LQ Newbie
 
Registered: Mar 2004
Posts: 14

Original Poster
Rep: Reputation: 0
Thx Snacy !!

That almost did the trick!! The only problem now is that it still writes the user who is logged in if I try to give the script a "bogus" name.. then I wan't it to report an error...
 
Old 03-06-2004, 07:03 AM   #5
snacky
Member
 
Registered: Feb 2004
Distribution: Debian
Posts: 286

Rep: Reputation: 30
Code:
#!/bin/bash
for i in $* ;do {
        if [ `w $i  -h |wc |awk -F\  '{print $1 }'` == 0 ] ; then echo\
        "$i is NOT logged in";
        else w $i |tail -n 1|awk -F\  '{print $1 }';
        fi
        };
done
Pardon my crappy formatting, I'm not very experienced at this.
 
Old 03-06-2004, 07:10 AM   #6
Cruger
LQ Newbie
 
Registered: Mar 2004
Posts: 14

Original Poster
Rep: Reputation: 0
Thumbs up

Thx for the help
 
Old 03-06-2004, 07:13 AM   #7
snacky
Member
 
Registered: Feb 2004
Distribution: Debian
Posts: 286

Rep: Reputation: 30
er, I just realized the 6th line would make WAY more sense if it were something like:
Code:
else echo "$i IS logged in"
 
  


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
users who logged before czezz Solaris / OpenSolaris 1 11-24-2004 07:12 AM
being logged out when using RM Jonpittam Linux - Software 2 09-30-2004 09:55 AM
kde much slower to start when logged in as alan than logged in as root arubin Slackware 0 04-26-2004 05:27 PM
who is logged in using sftp niehls Linux - Software 2 01-20-2004 06:37 PM
mozilla works fine when logged in as a user but crashes when logged in as root jimi Linux - General 6 04-02-2003 09:34 PM


All times are GMT -5. The time now is 01:25 PM.

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