blob: b6798f041d5d6b45fd537349d71f8e138e2a08e1 (
plain) (
blame)
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
|
#!/bin/sh
. /etc/rc
set -eu
CMD="$*"
HOSTNAME="$(hostname)"
FROM="cronjob@$HOSTNAME"
TIMEOUT='14400' # four hours
STATUS_F="$(mkstemp)"
CLOCK_F="$(mkstemp)"
OUT="$(mkstemp)"
email() {
{
cat <<-EOF
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
From: $FROM
To: root@localhost
Subject: (exit status: $(cat "$STATUS_F")) - $HOSTNAME: $CMD
EOF
cat "$OUT"
} | sendmail -t -f "$FROM"
}
trap 'email; rm -f "$OUT" "$STATUS_F" "$CLOCK_F"' EXIT
{
cat <<-EOF
Running commad: $CMD
Starting at: $(timestamp)
EOF
statusf "$STATUS_F" clock -o "$CLOCK_F" timeout "$TIMEOUT" nicely "$@"
cat <<-EOF
Finished at: $(timestamp)
Duration: $(minutes "$(cat "$CLOCK_F")")
EOF
} 2>&1 | pre "[$CMD]" | ts '%Y-%m-%dT%H:%M:%S' | tee "$OUT" >> /var/log/cronjobs.log
|