Find out the System users

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Find out the System users
# 1  
Old 03-16-2011
Bug Find out the System users

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

1. The problem statement, all variables and given/known data:
I want to create a file called Allusers that contains the list of
currently logged on users and the total number of them.
(note: it should print, The Total is: , at the end of the Allusers file)
I have made the command, and when i perform it , it show me all the users and it print the total of them. But my problem that the command doesn't save the result in the Allusers file.

2. Relevant commands, code, scripts, algorithms:

who
sort
tee
cat
echo
cat
wc

3. The attempts at a solution (include all code and scripts):


who | sort -t: -k1 | tee All |cat; echo Total; cat All |wc -l; rm All > Allusers


4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):

University of Newengland, Armidale, NSW, Australia
Dr.Paul Kwan, COMP170.
# 2  
Old 03-16-2011
If you want to have both written to the screen and written to the file, try this:
Code:
FILE=Allusers; MSG="Total is:"; who| cut -d " " -f1| sort| tee $FILE; echo $MSG; echo $MSG >> $FILE; who| wc -l| tee -a $FILE

If it is ok to just have it all in the file and list it's content with a cat:
Code:
$> FILE=Allusers; MSG="Total is:"; who| cut -d " " -f1| sort > $FILE; echo $MSG >> $FILE; who| wc -l >> $FILE

I used variables, since I am too lazy to write everything again and again and can change variable content at 1 point, not at all points where it is used in the code.

Issuing a who gives out a line with terminal information and maybe remote host info like:
Code:
root     pts/0        2011-03-14 10:09 (somehost.somedomain.org)

If you want just the user without any other information, so that cut is not needed anymore, issue a whoami for example.




Now to your code:

Code:
who | sort -t: -k1 | tee All |cat;

The tee writes stdin to stdout on the screen and to the file "All". The content is also piped over to cat, which is not needed.

Code:
echo Total;

This is just echoed to the screen, not into the file.

Code:
cat All |wc -l;

Your temporary file entries are counted, but only written to screen, not to a file, so they are lost too.

Code:
rm All > Allusers

You delete your temporary file and redirect stdin to the file. As this rm will work without producing any output to stdout, you write nothing into the file "Allusers" and sowith empty it. Though, there was never yet in this line of code being written anything into this file yet, so ironically you couldn't overwrite anything anyway.
# 3  
Old 03-16-2011
MySQL Find out the System users

Thank you MAN, Smilie

what a greate explanation Smilie

I have modified it and it is working well

Code:
 who| cut -d " " -f1| sort > Allusers; echo "The total is: " >> Allusers; who| wc -l >> Allusers

thank you again
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Users logged into the system

So I'm trying to write a single line command So I have to use last first in this command and I've figured out the format my professor wants it in, something like thislast | cut -d' ' -f1,15 | sort > check | uniq -c.... and I never can get it right, when I just last command I get something... (2 Replies)
Discussion started by: DoubleAlpha
2 Replies

2. UNIX for Dummies Questions & Answers

List system users and..

Hello i need fast help... script which will list only human users from /etc/passwd and find out if they have something in home. Thanks (11 Replies)
Discussion started by: mentoscz
11 Replies

3. Emergency UNIX and Linux Support

List of users on an AIX system

Is there a way to generate a list of users with name, user ID, and Security Group? It is urgent for audit purposes. Please help. (5 Replies)
Discussion started by: ggayathri
5 Replies

4. UNIX for Advanced & Expert Users

Best practices with AIX system users?

All, Preliminaries: AIX 5.2 Tivoli Maestro 6.1 (9.2) I am auditing an older AIX system. As it stands, I can login remotely to the system using the Maestro application's user account. This is BAD. The administrator claims that he cannot disable the remote login, because it will... (1 Reply)
Discussion started by: Thatto
1 Replies

5. Shell Programming and Scripting

Bash Help: users who are not logged into the system to display

A Newbie here, I am working on a script and am having problems with the else part of the script. I can't get the users who are not logged into the system to display on the screen with their username and the text "The user is not logged in". I am sure it is something simple and stupid, but I... (5 Replies)
Discussion started by: rchirico
5 Replies

6. Shell Programming and Scripting

How can i use system users in perl for login page

Hi, I want to code a script with perl. For this, I need some knowledge. How can i use system user name(with group) and password in my login page? I will be happy if you can help me (2 Replies)
Discussion started by: tahsinaltay
2 Replies

7. AIX

Default system users

Hello I have a question I have this users on my aix 5.3 box. This are a default users. lp:*:11:11::/var/spool/lp:/bin/false invscout:*:6:12::/var/adm/invscout:/usr/bin/ksh snapp:*:200:13:snapp login user:/usr/sbin/snapp:/usr/sbin/snappd ipsec:*:201:1::/etc/ipsec:/usr/bin/ksh... (2 Replies)
Discussion started by: lo-lp-kl
2 Replies

8. UNIX for Dummies Questions & Answers

Find users using system(List them only once)

Hey, got a few questions here for anyone who can help...... Command line to - display users using the system, but count them only once. Command line to - use the lastcomm command to display how many times ive used grep in october. Command line to - list all logged on users with at least 6... (3 Replies)
Discussion started by: xBuRnTx
3 Replies

9. UNIX for Advanced & Expert Users

AIX Unix.. number of users on system in a particular group

Does anyone know what pipe string might be used to determine how many people are logged onto an AIX system where a group ID begins with lets say 4. In other words, I am looking to query the system for the number of people currently logged onto a system that belong to any group starting with 4.... (1 Reply)
Discussion started by: afiore
1 Replies
Login or Register to Ask a Question