#!/opt/bin/perl # ######################################################################### # # # Program to send a mail to all users fulfilling certain conditions # # # ######################################################################### # # # Version 1.0 - Written 05.11.95 by Steffen Beyer # # # ######################################################################### # # # Copyright (C) 1995 by software design & management GmbH & Co. KG # # # ######################################################################### # # Some internal variables: # $version = 'version 1.0'; # $self = $0; $self =~ s!^.*/!!; # # Who am I? (effective UID, real UID not necessary) # ($sender) = (getpwuid($>))[0]; # $mailfile = "/u/$sender/.$self.txt"; # $tempfile = "/tmp/$self.tmp.$$"; # # Process passwd file: # setpwent; # while (($user,$passwd,$uid,$gid,$quota,$comment,$gcos,$dir,$shell) = getpwent) { # # Define here the condition wether user receives a mail or not: # if (-f "$dir/public/$user.html") { unless(open(TEMPFILE, ">$tempfile")) { die "$self: can't write '$tempfile': $!\n"; } print TEMPFILE "From: $sender@sdm.de\n"; print TEMPFILE "To: $user@sdm.de\n"; unless(open(MAILFILE, "<$mailfile")) { $rc = $!; close(TEMPFILE); unlink($tempfile); die "$self: can't read '$mailfile': $rc\n"; } $first = 1; while () { if ($first) { print TEMPFILE "Subject: $_"; print TEMPFILE "\n"; $first = 0; } else { print TEMPFILE $_; } } close(MAILFILE); close(TEMPFILE); if (! $first) { if ((system("cat $tempfile | sendmail -t") >> 8) != 0) { warn "$self: can't send mail to $user@sdm.de!\n"; } } unlink($tempfile); } } # endpwent; # # Done. #