Simple loop to mail all active users.

Login to Reply

Thread Tools Search this Thread
# 1  
Old 11-08-2016
Simple loop to mail all active 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:
Send a fortune to all active/logged in users

2. Relevant commands, code, scripts, algorithms:
So I understand I need to use the who command to see all the active users online. Then mail those users a fortune using the built in fortune command. The issue I'm having is how I would put this into a for loop?
Do I simply create a log of all active users and awk that? I'm sorry I am having a really hard time with shell scripting and cant grasp my head around the logic behind this simple one line of code.

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

4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
Modesto Junior College, Modesto (CA), US, Dale Phillips, and CMSCI-210:

Thank you for the help. I know theres not to much information but thats why im here Smilie. Try and get a push in the right direction.

Last edited by rbatte1; 11-08-2016 at 12:38 PM.. Reason: Retro-fitted the template so that this makes sense.
# 2  
Old 11-08-2016
Hi, you can use shell variables to capture the necessary information from the command and use these variables with the mail command. This should be done in a loop, either a for loop or a while loop using the read command. There are many examples of either form of loops on these forums.
# 3  
Old 11-08-2016
So you seem to know how a for loop is structured. You could use "command substitution" to provide a list of items from who for the for construct. While awk comes in handy frequently, here you can do without it. A "command substitution" of fortune could be used for the mail command.
# 4  
Old 11-08-2016
Appreciate the replies so soon xD. Do you have a useful link to "command substitution"? Have not heard that term yet.
# 5  
Old 11-08-2016
Although usually frowned upon in these fora:
man bash (or man ksh)
# 6  
Old 11-09-2016
Just for clarity, it is usually frowned upon in regard that we try not to say "Read the manual", bot that using command substitution is frowned upon - I use command substitution all the time.

Kind regards,
Robin (having a frown Smilie) Smilie
# 7  
Old 11-09-2016
Originally Posted by RudiC
Although usually frowned upon in these fora:
man bash (or man ksh)
Sorry for such a late reply had life getting in way. But what exactly am I looking for in the man. I've looked all over and cannot find anything about command substitution but I may just be blind also Smilie.
Login to Reply

Thread Tools Search this Thread
Search this Thread:
Advanced Search

Similar Threads More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Search the string in the active log and send mail balareddy Shell Programming and Scripting 1 05-13-2014 09:42 AM
Authenticate AIX users from MS Active Directory kah00na AIX 3 02-28-2011 12:21 PM
Loop script required within an active log file Henk Trumpie Shell Programming and Scripting 3 01-24-2011 07:06 AM
keep mail command active inside a script on unix iga3725 Shell Programming and Scripting 4 10-19-2010 02:05 PM
control permissions for Active Directory users on AIX xia777 UNIX for Dummies Questions & Answers 1 04-20-2010 05:44 AM
Command for list of active/disabled users Mike1234 Linux 1 07-28-2008 05:58 PM
Active / Non Active users ? varungupta UNIX for Advanced & Expert Users 3 05-12-2008 12:00 AM
All times are GMT -4. The time now is 05:09 PM.

Unix & Linux Forums Content Copyright 1993-2018. All Rights Reserved.
Show Password

Not a Forum Member?
Forgot Password?