LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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 07-15-2010, 06:47 AM   #1
recar
LQ Newbie
 
Registered: Jul 2010
Posts: 1

Rep: Reputation: 0
linux script to display all users


Hi can anybody help with with shell scripting.I need a script to display all users in system.i know there are commands to display all users but i need a script for that.hope someone can share the script.
 
Old 07-15-2010, 06:56 AM   #2
wertik
LQ Newbie
 
Registered: Sep 2008
Location: Russia,city - Moscow
Distribution: Slackware ,Ubuntu, Debian, Fedora
Posts: 3

Rep: Reputation: 0
Quote:
Originally Posted by recar View Post
Hi can anybody help with with shell scripting.I need a script to display all users in system.i know there are commands to display all users but i need a script for that.hope someone can share the script.
??

#!/bin/sh
who
#EOF
 
Old 07-15-2010, 06:57 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,006

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
What have you tried? It is all well and good to ask a question but without information or parameters the answers you get could be almost anything.
For example:
Code:
cat /etc/passwd
Now its not very useful on its own but all the usernames will be there somewhere.
 
Old 07-15-2010, 07:06 AM   #4
rdgreenlaw
Member
 
Registered: May 2007
Location: Newport, Maine, USA
Distribution: Debian 8.7
Posts: 73

Rep: Reputation: 18
If you simply want to see who is on the system use the who command.

Just type who and press enter. This produces a list of users currently on the system, their terminal or port number, date logged in, time logged in and if attached to a display the display number.

If you simply want the user names and nothing else use the following code:

Code:
who | awk -F " " '{print $1}'
To make a script, use the following:

Code:
#!/bin/sh

# filename: whoisloggedon

who | awk -F " " '{print $1}'

Don't forget to make the script executable

chmod 766 whoisloggedon
 
Old 07-15-2010, 07:24 AM   #5
rdgreenlaw
Member
 
Registered: May 2007
Location: Newport, Maine, USA
Distribution: Debian 8.7
Posts: 73

Rep: Reputation: 18
I gave you a script to show who was logged in. If you want to see real users names even if they are not logged in use this instead:

Code:
#!/bin/sh
# filename: whocanlogon

cat /etc/passwd | awk -F ":" '{if $3 ==0 || ($3> 999 && $3 < 65534)) print $1}'
 
  


Reply



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
display erro log in linux using shell script venu_babu Programming 1 08-31-2008 03:01 PM
Display Linux users boybawang Linux - Newbie 3 09-26-2006 03:20 AM
Linux Command login screen, Display Script? roclok Linux - Software 2 06-14-2006 12:22 AM
[FC2]Why does the users command display multiple users? Harkov Fedora 1 07-10-2004 09:24 PM
Linux Users created via Script ??? HOW ?? Lutzer Linux - Networking 1 07-31-2002 04:03 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:24 AM.

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
Open Source Consulting | Domain Registration