-
Notifications
You must be signed in to change notification settings - Fork 2
/
copy
executable file
·62 lines (48 loc) · 1.34 KB
/
copy
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
#!/bin/bash
# copy profiles
# 1st arguments is regexp
if [ "$USER" == 'root' ]; then
sudo=""
else
sudo="sudo"
fi
usage() {
cat <<EOF
Usage: copy <glob>
Copy the *<glob>*.json.gz profiles to the destination.
Example: copy node24[0-1]*golett
Add quotes around the glob to prevent bash from expanding
them before passing them to this script.
You can also pass a second argument 'notify', to notify
hosts that had new profiles copied.
EOF
exit 4
}
glob=`echo $1 | sed "s/\s/_/g; s/;/_/g"`
shift
notify=$1
if [ -z "$glob" ]; then
usage
else
cpout=`$sudo /bin/cp -f build/xml/*$glob*.json.gz /var/www/https/profiles/ 2>&1`
if [ $? -eq 0 ]; then
echo "Copied build/xml/*$glob*.json.gz to /var/www/https/profiles/"
else
echo "ERROR: failed to copy build/xml/*$glob*.json.gz to /var/www/https/profiles/: $cpout"
exit 1
fi
if [ "$notify" == "notify" ]; then
notified=""
for host in `ls build/xml/*$glob*.json.gz | sed "s#build/xml/##;s/.json.gz//"`; do
echo "ccm.`date +%s`" > /dev/udp/$host/7777
if [ $? -eq 0 ]; then
notified="$notified $host"
else
echo "ERROR: failed to notify $host"
fi
done
if [ ! -z "$notified" ]; then
echo "Notified host(s)$notified"
fi
fi
fi