-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmq.daily
executable file
·124 lines (102 loc) · 2.52 KB
/
mq.daily
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/local/bin/perl
use Time::Local;
my $sendmail = "/usr/lib/sendmail";
#my $sendmail = "cat -;echo";
# cfg #
local($basepath) = '/home/projects/must/minimust/';
# cfg #
my($listcfg) = shift @ARGV;
my($listcmd) = shift @ARGV;
if(!defined $listcfg) {
print "Available lists:\n";
foreach(<$basepath/list/*>) {
if(-d $_ && -r "$_.cfg") {
/[^\/]+$/;
print "\t$&\n";
}
}
exit;
}
my($listcfgpath) = "/home/projects/must/minimust/list/$listcfg.cfg";
die "'$listcfgpath' does not exist...\n" unless -f $listcfgpath;
local(%listmembers,$list,$listalias,$listname,$defaultadmincmd,$listpath,$firstmsg);
#------------- Read Config ---------------#
my($ret);
unless($ret = do $listcfgpath) {
die "couldn't parse $listcfgpath: $@" if $@;
die "couldn't do $listcfgpath: $!" unless defined $ret;
die "couldn't run $listcfgpath" unless $ret;
}
#------------- Read Config ---------------#
if($listcmd eq 'daily') {
my($datestr) = scalar localtime(time);
my($head) = <<EOM;
To: $listname <$list>
From: $listname <$list>
MIME-Version: 1.0
Subject: $listname.daily ($datestr)
Content-Type: TEXT/PLAIN; charset=iso-8859-1
Content-Transfer-Encoding: 8BIT
X-Mailer: $version
EOM
foreach(keys %listmembers) {
my($p) = 0;
my($gnu);
$gnu=`/home/projects/must/minimust/mq $listcfg list $_`;
if(length $gnu) {
open(MAIL,"|$sendmail $_")||die "Can't mail...";
print MAIL $head;
print MAIL "Hello $_:\n\n";
$p = 1;
print MAIL "Your open cases:\n$gnu";
}
$gnu = "";
if($listmembers{$_} !~ /\bnodist\b/) {
$gnu=`/home/projects/must/minimust/mq $listcfg list unassign`;
}
if(length $gnu && !$p) {
open(MAIL,"|$sendmail $_")||die "Can't mail...";
print MAIL $head;
print MAIL "Hello $_:\n";
$p = 1;
}
print MAIL "\nUnassigned cases:\n$gnu" if length $gnu;
close(MAIL);
}
exit;
}
if($listcmd eq 'weekly') {
print STDERR "Not implemented yet =)\n";
getweekid();
exit;
}
die "No command ?\n";
# EOF
sub findlastweek {
my $wday = (localtime(time))[6];
my($starttime) = time-60*60*24*($wday+6);
my(@result);
for(0..6) {
my($y,$m,$d) = (localtime($starttime))[5,4,3];
$y += 1900;
$m ++;
push @result,sprintf("%4d%02d%02d",$y,$m,$d);
$starttime += 60*60*24;
}
return @result;
}
sub getweekid {
my(@week) = findlastweek();
foreach my $w (keys %weekmon) {
for my $i (<$basepath/list/$listcfg/*/*.status>,
<$basepath/list/$listcfg/*.status>) {
/([^\/]+)\.status$/;
my($ett) = $1;
print "$ett\n" if checkit($_);
}
}
}
sub checkit {
my($path) = @_;
/([^\/]+)\.status$/;
}