LinuxQuestions.org
Review your favorite Linux distribution.
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 05-25-2006, 02:28 PM   #1
RagedPenguin
LQ Newbie
 
Registered: Mar 2006
Posts: 5

Rep: Reputation: 0
user list


How do you send out an email in 'reverse order' of all the users currently logged into a Linux server, while storing the command in a background process?

I'm using standard telnet + putty, and I'm definately a linux newb lol

Thanks for any help. I've been reading my guide to linux book, but I'm still confused.

Last edited by RagedPenguin; 05-25-2006 at 02:45 PM.
 
Old 05-25-2006, 03:11 PM   #2
jeelliso
Member
 
Registered: Oct 2005
Location: Knoxville, Tn (USA)
Distribution: OpenSUSE, Ubuntu
Posts: 250

Rep: Reputation: 30
I thought there was a command you could use to send a message to all current users, but I can't seem to find it.

I would probably just write a small shell script with a for loop. For each line of
Code:
who
(which shows users logged on) it could use the mail command to send an email to them. Just start from the back of the list in your for loop to do it in reverse order.

If you've ever written a shell script before, I would suggest looking over a small tutorial. It wouldn't do you any good if I just told you the answer, as it would be a pretty simple script.

Good Luck,

~Justin
 
Old 05-25-2006, 03:17 PM   #3
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,075
Blog Entries: 14

Rep: Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251
What do you mean by "reverse order". Alphabetically? Time of login?

Short and simple:

for USER in `who |awk '{print $1}' |sort -u`
do echo mailtextfile | mail -s "Mail from me" $USER
done

In the above USER is a variable name you picked (you could call it MUD or anything else that appeals to you). $USER is a reference back to the same variable (so if you use MUD you need to use $MUD).

The who command shows all logged in users.

The awk command says to only print the first field of the who output (this is the user name).

The sort -u tells it to list each user only once (in case they have multiple logins).

mailtextfile is abitrary - it is any filename you want (mudtext for example). In that file you put the text you wish to email.

The item in quotes after mail -s is the subject you want.

Finally $USER (or $MUD etc...) is the user name to send the mail to.

Note that the above will send the mail to the user's Linux/Unix mail box. If you've set up forwarding and aliases in sendmail for all users it will be handled by that. If you haven't and your users don't typically read their Linux/Unix mail they're unlikely to see the mail.

If you have user accounts on your Linux server that are the same as those used in your external mail then you modify the $USER to be ${USER}.domain.top. (You need the brackets so it will know that USER is the variable rather than USER.domain.top.) The domain.top is whatever your user email accounts use as top level and local domain (example yahoo.com, apache.org etc...).
 
Old 05-25-2006, 03:20 PM   #4
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,075
Blog Entries: 14

Rep: Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251
By the way if you're just trying to send a message to everyone currently logged in you can use the "wall" command. Just type "wall". Input the message you want to send then hit Ctrl-D to end the message. It will appear on the screen of everyone logged in. (Note that some people get very annoyed by that however - usually it is done when you need to take the system down.)

Note that "wall" does NOT send an email but rather writes directly to the users' terminals.
 
Old 05-25-2006, 03:22 PM   #5
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,397
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
What do you mean 'reverse order'?

Logins seem to be an unordered list. I guess you could sort by UID, Username, login time/date, color of socks, process ID's....

But there's more. Sending e-mails has no guarantee that they will ultimatley be sent or received in any particular order, unless you actually wait to see that a sent e-mail was received before sending the next one.

Maybe you should explain what you really want to do.

--- rod.
 
Old 05-25-2006, 04:19 PM   #6
RagedPenguin
LQ Newbie
 
Registered: Mar 2006
Posts: 5

Original Poster
Rep: Reputation: 0
thank you for very much for the help so far guys. Yes sorry for not elaborating, reversed order is supposed to be by alphabetical order of usernames on the network and to send that list in a standard email.

Last edited by RagedPenguin; 05-25-2006 at 05:09 PM.
 
Old 05-25-2006, 06:09 PM   #7
RagedPenguin
LQ Newbie
 
Registered: Mar 2006
Posts: 5

Original Poster
Rep: Reputation: 0
yeah and it isn't supposed to be in a script, just a basic command.
I managed to do the command that I needed for the process, thanks so much for all your help. I thought it was a lot more complicated then it turned out to be lol.
Next time I'll try to be more clear, sorry for the confusion.

Last edited by RagedPenguin; 05-25-2006 at 06:44 PM.
 
  


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
How to list user in Linux box, add an user to a group! steady_lfcfan Linux - Newbie 12 01-27-2013 02:14 PM
How to list files from a certain user?? Drunkalot Linux - General 1 06-20-2005 06:11 AM
PHP List /home/'user' then finger 'user' Caboose Programming 1 09-22-2004 05:12 AM
default user list PlatinumRik Linux - Security 1 04-27-2004 07:35 PM
DCgui User list mrsolo Linux - Software 1 05-10-2003 06:52 PM

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

All times are GMT -5. The time now is 09:54 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