Improve company productivity with a Business Account.Sign Up

x
?
Solved

Setting a allusers email

Posted on 2000-02-28
11
Medium Priority
?
249 Views
Last Modified: 2013-12-16
Hi There
I need to setup a email that will email every user on the system
has anyone got any ideas how to do it

Phil
0
Comment
Question by:will_do
  • 6
  • 5
11 Comments
 
LVL 40

Expert Comment

by:jlevie
ID: 2566894
Well, you could create an alias that included all user names, but that gets very unwieldy for a large number of users. You could also create a list of users and use a shell script to read the list and send the emails, but then you need to keep the list up to date. The last way, which I use, is to use a perl script to walk the password file, skipping system and a few other accounts and mailing a message to all others.

I can't get to the perl code from where I am now, but I'll get it and paste it into a comment later this evening.
0
 

Author Comment

by:will_do
ID: 2566905
Thankyou
0
 
LVL 40

Accepted Solution

by:
jlevie earned 200 total points
ID: 2570823
Here tis...

#!/usr/bin/perl
#
# NAME
#       mailer - all user emailer
#
# SYNOPSIS
#       mailer from subj msg
#
# DESCRIPTION
#
#       Mailer sends the data in the "msg" file to each user account listed in
#       the system's password file (except for those in the "skip" list
#       below). The "From:" and "Subject:" header lines are built with the
#       data contained in the "from" and "subj" arguments, or sent inline if the
#       mail program allows.
#
#       On on older Solaris or other systems that don't have a readily avalable
#       mailer that accepts in "Subject" and "From" args, a temp file is built in
#        /tmp/mailer-temp that contains the header lines and message. This
#       is controlled by the "$usetmp" variable below.
#
#       Note: systems other than Linux or Solaris may require a tweak to
#       the "system" line that mails the message.
#
#       Author: James K. Levie
#

#
# Whether or not to use a temp file.
#
$usetmp = 0;
#
# A list of user accounts to skip.
#
@skip = ("root", "bin", "daemon", "adm", "lp", "sync", "shutdown",
         "halt", "mail", "news", "uucp", "operator", "games", "gopher",
         "ftp", "nobody", "xfs");

if($#ARGV!=2)
{
  die "Useage: mailer from subject message-file\n";
}

if($usetmp)
{
  $TMPF = "/tmp/mailer-temp";
  open(MSG, "$ARGV[2]") || die "Can't open message file <$ARGV[2]>\n";
  open(TMP, ">$TMPF") || "Can't create temp file <$TMPF>\n";
  #
  # Put the headers into the tmp file
  #
  print TMP "From: $ARGV[0]\n";
  print TMP "Subject: $ARGV[1]\n\n";
  #
  # Copy the message into the temp file
  #
  while(<MSG>) { print TMP; }
  close(MSG);
  close(TMP);
}
#
# Walk the passwd file
#
while(($name) = getpwent)
{
  $sendit = 1;
  #
  # Check the list of system accounts and other accounts
  # that shouldn't get the email against this username.
  #
  foreach $skipit (@skip)
  {
    if(($name=~/$skipit/)) { $sendit = 0; last:}
  }
  if($sendit)
  {
    #
    # Okay mail it.
    #
    if($usetmp)
    {
      system "mail -w $name <$TMPF";
    }
    else
    {
      system "mail -s \"$ARGV[1]\" $name <$ARGV[2]";
    }
    #
    # Brag about it...
    #
    print "Sent to $name\n";
  }
}
if($usetmp) { unlink($TMPF); }
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:will_do
ID: 2572103
thankyou
but how do i set it up
where do i put the script?
do i add a allusers account?
sorry i'm very new to linux
0
 

Author Comment

by:will_do
ID: 2572142
thankyou
but how do i set it up
where do i put the script?
do i add a allusers account?
sorry i'm very new to linux
0
 
LVL 40

Expert Comment

by:jlevie
ID: 2573148
Okay, open a new file named "mailer" and paste the perl code into it. Close the file and make it executable with "chmod +x mailer". If you only want to use it from one account, just leave "mailer" in that user's home dir, otherwise you could copy the file to someplace that multiple users can get to, like /usr/local/bin or /usr/bin.

To use it, create a file containing the message and invoke the utility like "mailer sender "The Subject" message-file".
0
 

Author Comment

by:will_do
ID: 2573998
Thanks jlevie once again
but i just get mailer command not found when i type in mailer sender

0
 
LVL 40

Expert Comment

by:jlevie
ID: 2574060
If you are in the directory that you've created the mailer script file in, it might be that the current directory isn't in your path. Try "./mailer sender "A subject" msg-file". If that fails, make sure that it's executable:

levie> ls -l mailer
-rwxrwxr-x   1 levie    staff        2211 Feb 29 17:09 mailer*

The "x"s above indicate executable mode for user, group, and other.
0
 

Author Comment

by:will_do
ID: 2574152
ok i think i have got it

but this comes up
[root@phil allusers]# mailer sender "The Subject" message"




and the > just keep coming until you use ctrl c

0
 
LVL 40

Expert Comment

by:jlevie
ID: 2574181
There's an extra " at the end of the line after message. There have to "s around the second argument as a subject will usually contain spaces.
0
 

Author Comment

by:will_do
ID: 2574208
cool thankyou i got it

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
This article explains how to use the rsync command to create backups and sync data across hosts. Rsync is a very useful command that is often used to copy data, make backups, migrate hosts, and bridge the gap between site staging and production envi…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question