-
Notifications
You must be signed in to change notification settings - Fork 0
/
syncall.sh
55 lines (47 loc) · 1.2 KB
/
syncall.sh
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
#!/bin/bash
echo Mirror Sync Script
mirrors=( archlinux centos ubuntu-releases ubuntu )
dir=/opt/mirrorsync/scripts
arg=""
errors=0
exitcode=1
emailrecepient="[email protected]" // change this
emailsender="`whoami`@`hostname`"
emailsubject="Error while syncing linux mirrors on `hostname -s`"
format=" %-30s %-20s %-10s\n"
mailfile="$dir/status.mail"
function sync {
for i in "${mirrors[@]}"
do
($dir/$i.sh $arg)
exitcode=$?
if [[ $exitcode -ne "0" ]]
then
(( errors += 1 ))
fi
printf "$format" "`date`" "$i" "$exitcode" >> $mailfile
sleep 5
done
}
if [[ $1 == "debug" ]]
then
arg="debug"
fi
printf "" > $mailfile
printf "<pre>\n" >> $mailfile
printf "$format" "TIMESTAMP" "MIRROR" "EXITCODE" >> $mailfile
sync
printf "</pre>" >> $mailfile
if [[ $errors -ne "0" ]]
then
echo sending mail
( (
echo To: $emailrecepient
echo From: $emailsender
echo "Content-Type: text/html; "
echo Subject: $emailsubject
echo
cat $mailfile
) | sendmail -t)
fi
(rm $mailfile)