3 # send e-mail to all registered F*EX users
5 # Author: Ulli Horlacher <framstag@rus.uni-stuttgart.de>
13 exit if $ENV{SCRIPT_NAME};
15 unless ($ENV{FEXLIB}) {
17 $ENV{FEXLIB} = $ENV{FEXHOME}.'/lib';
19 $ENV{FEXLIB} = dirname(dirname(abs_path($0))).'/lib';
22 $FEXLIB = $ENV{FEXLIB};
23 die "$0: no FEXLIB\n" unless -f "$FEXLIB/fex.pp";
28 # become effective user fex
30 if (my @pw = getpwnam('fex')) {
35 die "$0: no such user 'fex'\n";
40 our ($FEXHOME,$hostname,$sendmail,$spooldir,$admin,$bcc);
42 # load common code, local config : $HOME/lib/fex.ph
43 require "$FEXLIB/fex.pp" or die "$0: cannot load $FEXLIB/fex.pp - $!\n";
45 die "$0: \$admin not configured in $FEXLIB/fex.ph\n"
46 if not $admin or $admin =~ /example.org/;
50 getopts('h') or usage(2);
54 die usage(1) unless $subject;
58 die usage(1) unless $text;
60 if (open my $sig,$ENV{HOME}.'/.signature') {
61 $text .= "\n-- \n" . <$sig>;
67 chdir $spooldir or die "$0: $spooldir - $!\n";
69 # @users = grep { chomp;s:/@:: } glob("*/@");
70 foreach $user (glob("*@*")) {
71 if (-f "$user/@" and (readlink "$user/\@NOTIFICATION"||'') !~ /no/i) {
76 foreach $group (glob "*/\@GROUP/*") {
77 if (open $group,$group) {
81 push @users,$_ if /@/;
87 foreach $subuser (glob "*/\@SUBUSER") {
88 if (open $subuser,$subuser) {
92 push @users,$_ if /@/;
98 # @users = qw'framstag@fex';
99 die "$0: no users found\n" unless @users or grep /@/,@users;
101 @users = uniq(@users);
103 open $sendmail,'|-',$sendmail,@users or die "$0: $sendmail - $!\n";
107 "To: fexusers\@$hostname\n",
108 "Subject: $subject\n",
112 close $sendmail or die "$0: $sendmail - $!\n";
113 print "mail sent to:\n",map { "$_\n" } @users;
122 print "usage: $0 \"SUBJECT\" < mail.text\n";