-
Notifications
You must be signed in to change notification settings - Fork 0
/
mailman-crontab-edit
executable file
·47 lines (38 loc) · 1.03 KB
/
mailman-crontab-edit
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
#!/usr/bin/python
# This script inserts the mailman user name into the crontab entries after
# the 5 time/date fields so that it can be installed under /etc/cron.d
#
# usage: mailman-crontab-edit [-s src_file] [-u mailman_user] [-d dst_file]
# src_file defaults to stdin
# mailman_user defaults to mailman
# dst_file defaults to stdout
import sys, re, getopt
srcFile = None
dstFile = None
mmUser = None
opts, args = getopt.getopt(sys.argv[1:], "s:d:u:")
for o, a in opts:
if o == "-s":
srcFile = a
if o == "-d":
dstFile = a
if o == "-u":
mmUser = a
if srcFile:
inFD = open(srcFile)
else:
inFD = sys.stdin
if dstFile:
outFD = open(dstFile, mode='w')
else:
outFD = sys.stdout
if not mmUser:
mmUser = "mailman"
comment_re = re.compile(r'^\s*#')
time_date_re = re.compile(r'(^\s*(\S+\s+){5,5})')
for line in inFD:
if not comment_re.search(line):
match = time_date_re.search(line)
if match:
line = time_date_re.sub(r'\1 %s ' % mmUser, line)
print >>outFD, line,