Solved

Setting a allusers email

Posted on 2000-02-28
11
245 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 50 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
Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

 

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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

rdate is a Linux command and the network time protocol for immediate date and time setup from another machine. The clocks are synchronized by entering rdate with the -s switch (command without switch just checks the time but does not set anything). …
If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses

628 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