Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Setting a allusers email

Posted on 2000-02-28
11
Medium Priority
?
246 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 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

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

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
Fine Tune your automatic Updates for Ubuntu / Debian
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…
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

664 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