Solved

Setting a allusers email

Posted on 2000-02-28
11
236 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
Comment Utility
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
Comment Utility
Thankyou
0
 
LVL 40

Accepted Solution

by:
jlevie earned 50 total points
Comment Utility
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
 

Author Comment

by:will_do
Comment Utility
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
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 40

Expert Comment

by:jlevie
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
cool thankyou i got it

0

Featured Post

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

This is the error message I got (CODE) Error caused by incompatible libmp3lame 3.98-2 with ffmpeg I've googled this error message and found out sometimes it attaches this note "can be treated with downgrade libmp3lame to version 3.97 or 3.98" …
Network Interface Card (NIC) bonding, also known as link aggregation, NIC teaming and trunking, is an important concept to understand and implement in any environment where high availability is of concern. Using this feature, a server administrator …
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
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.

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now