Unix/Linux Go Back    


Homework & Coursework Questions Students must use and complete the template provided. If you don't, your post may be deleted! Special homework rules apply here.

Simple loop to mail all active users.

Homework & Coursework Questions


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 11-08-2016   -   Original Discussion by kjcraig77
kjcraig77 kjcraig77 is offline
Registered User
 
Join Date: Nov 2016
Last Activity: 9 November 2016, 10:58 AM EST
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
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 Linux. 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.
Sponsored Links
    #2  
Old Unix and Linux 11-08-2016   -   Original Discussion by kjcraig77
Scrutinizer's Unix or Linux Image
Scrutinizer Scrutinizer is offline Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 21 November 2017, 11:11 PM EST
Location: Amsterdam
Posts: 11,625
Thanks: 517
Thanked 3,381 Times in 2,980 Posts
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.
Sponsored Links
    #3  
Old Unix and Linux 11-08-2016   -   Original Discussion by kjcraig77
RudiC RudiC is online now Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 22 November 2017, 5:52 AM EST
Location: Aachen, Germany
Posts: 11,643
Thanks: 320
Thanked 3,618 Times in 3,323 Posts
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 Unix and Linux 11-08-2016   -   Original Discussion by kjcraig77
kjcraig77 kjcraig77 is offline
Registered User
 
Join Date: Nov 2016
Last Activity: 9 November 2016, 10:58 AM EST
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
Appreciate the replies so soon xD. Do you have a useful link to "command substitution"? Have not heard that term yet.
Sponsored Links
    #5  
Old Unix and Linux 11-08-2016   -   Original Discussion by kjcraig77
RudiC RudiC is online now Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 22 November 2017, 5:52 AM EST
Location: Aachen, Germany
Posts: 11,643
Thanks: 320
Thanked 3,618 Times in 3,323 Posts
Although usually frowned upon in these fora:
man bash (or man ksh)
Sponsored Links
    #6  
Old Unix and Linux 11-09-2016   -   Original Discussion by kjcraig77
rbatte1 rbatte1 is offline Forum Staff  
Root armed
 
Join Date: Jun 2007
Last Activity: 21 November 2017, 12:04 PM EST
Location: Lancashire, UK
Posts: 3,373
Thanks: 1,456
Thanked 665 Times in 598 Posts
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 Linux) Linux
Sponsored Links
    #7  
Old Unix and Linux 11-09-2016   -   Original Discussion by kjcraig77
kjcraig77 kjcraig77 is offline
Registered User
 
Join Date: Nov 2016
Last Activity: 9 November 2016, 10:58 AM EST
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by RudiC View Post
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 Linux.
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
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 07:01 AM.