1 | #!/bin/sh
|
---|
2 | #
|
---|
3 | # Mega simple wrapper for batch control on nodes.
|
---|
4 | #
|
---|
5 | # Rick van der Zwet <rick@wirelessleiden.nl>
|
---|
6 | #
|
---|
7 |
|
---|
8 | HOSTS=${*:-"`$(dirname $0)/gformat.py list up systems fqdn`"}
|
---|
9 | PREFIX=${PREFIX:-'ip'}
|
---|
10 | CMD=${CMD:-'md5 /usr/local/etc/rc.d/lvrouted'}
|
---|
11 |
|
---|
12 | echo "# WARN: Going to run at: " $HOSTS; sleep 2
|
---|
13 | scp_files=""
|
---|
14 | concurrent=true
|
---|
15 |
|
---|
16 | ##
|
---|
17 | ## Network differences
|
---|
18 | ##
|
---|
19 | #cat << 'EOF' >/tmp/command
|
---|
20 | #sh -c ". /etc/rc.subr; load_rc_config "networking"; set" > /tmp/networking-env
|
---|
21 | #grep -e ^ifconfig -e ^ipv4 /tmp/networking-env
|
---|
22 | #{ grep -e ^ipv4 /tmp/networking-env | cut -d= -f2 | tr -d \' | xargs -n1 | cut -d/ -f1;
|
---|
23 | # grep -e ^ifconfig /tmp/networking-env | grep -v -i 'dhcp' | cut -d= -f2 | tr -d \' | cut -d' ' -f2 | cut -d'/' -f1
|
---|
24 | #} | sort -u > /tmp/config
|
---|
25 | #ifconfig -a | grep 'inet ' | cut -d' ' -f2 | sort > /tmp/current
|
---|
26 | #echo "# Comparing IP differences /tmp/current vs /tmp/config"
|
---|
27 | #diff -u /tmp/current /tmp/config
|
---|
28 | #EOF
|
---|
29 |
|
---|
30 | ##
|
---|
31 | ## Migrate SSH authorized_keys symlink to new location.
|
---|
32 | ##
|
---|
33 | #cat <<'EOF' > /tmp/command
|
---|
34 | #mount -uwo noatime / && unlink /root/.ssh && mkdir /root/.ssh && ln -s /etc/ssh/authorized_keys /root/.ssh/ && mount -ur
|
---|
35 | #EOF
|
---|
36 |
|
---|
37 | ##
|
---|
38 | ## View lvrouted configured flags and processes
|
---|
39 | ##
|
---|
40 | #cat <<'EOF' > /tmp/command
|
---|
41 | #/usr/local/etc/rc.d/lvrouted rcvar | grep flags
|
---|
42 | #pgrep -fl lvrouted
|
---|
43 | #EOF
|
---|
44 |
|
---|
45 | ##
|
---|
46 | ## Restart lvrouted
|
---|
47 | ##
|
---|
48 | #cat <<'EOF' > /tmp/command
|
---|
49 | #sleep 30
|
---|
50 | #nohup /usr/local/etc/rc.d/lvrouted restart
|
---|
51 | #EOF
|
---|
52 |
|
---|
53 | ##
|
---|
54 | ## Sync some files
|
---|
55 | ##
|
---|
56 | #scp_files="/tmp/wl-config /tmp/nameserver-shuffle"
|
---|
57 | #cat <<'EOF' > /tmp/command
|
---|
58 | #mount -uwo noatime / || exit 1
|
---|
59 | #trap "mount -ur /; exit 1" 1 2 3 15
|
---|
60 | #trap "mount -ur /; exit 0" 0
|
---|
61 | #
|
---|
62 | #cp -v /tmp/wl-config /tools || exit 1
|
---|
63 | #cp -v /tmp/nameserver-shuffle /tools || exit 1
|
---|
64 | #
|
---|
65 | #mount -ur / || exit 1
|
---|
66 | #/tools/wl-config -b || exit 1
|
---|
67 | #/tools/nameserver-shuffle || exit 1
|
---|
68 | #EOF
|
---|
69 |
|
---|
70 | ##
|
---|
71 | ## Run /tools/wl-config with random scheduler to avoid gold-rush and killing the
|
---|
72 | ## config generator server
|
---|
73 | ##
|
---|
74 | cat <<'EOF' > /tmp/command
|
---|
75 | sleep `expr $$ % 300`
|
---|
76 | /tools/wl-config -b || exit 1
|
---|
77 | /tools/nameserver-shuffle || exit 1
|
---|
78 | EOF
|
---|
79 |
|
---|
80 | ##
|
---|
81 | ## Detect routing loops and find out the actual default route
|
---|
82 | ##
|
---|
83 | ## Process output with:
|
---|
84 | ## a) Proxy per host:
|
---|
85 | ## for F in ip-*.txt; do printf "%-20s : %s\n" `echo "$F" | awk -F'[-.]' '{print $2}'` `grep -v '*' $F | tail -1 | awk '{print $2}'`; done
|
---|
86 | ## b) Count per proxy:
|
---|
87 | ## for F in ip-*.txt; do printf "%-20s : %s\n" `echo "$F" | awk -F'[-.]' '{print $2}'` `grep -v '*' $F | tail -1 | awk '{print $2}'`; done | awk '{print $3}' | sed 's/^2[a-z0-9-]*\.//g' | sort | uniq -c
|
---|
88 | ##
|
---|
89 | #cat << 'EOF' > /tmp/command
|
---|
90 | #traceroute -m 15 -w 1 -q 1 -I rvdzwet.nl
|
---|
91 | #EOF
|
---|
92 |
|
---|
93 |
|
---|
94 | # Cleanup old entries
|
---|
95 | rm $PREFIX-* stderr-*
|
---|
96 |
|
---|
97 | for HOST in $HOSTS; do
|
---|
98 | echo "# Working on $HOST"
|
---|
99 | stdout_file="$PREFIX-${HOST%%.}.txt"
|
---|
100 | stderr_file="stderr-${HOST%%.}.txt"
|
---|
101 | : > $stdout_file
|
---|
102 | : > $stderr_file
|
---|
103 | if $concurrent; then
|
---|
104 | {
|
---|
105 | if [ -n "$scp_files" ]; then
|
---|
106 | scp -o ConnectTimeout=3 -o BatchMode=yes $scp_files root@$HOST:/tmp || exit 1
|
---|
107 | fi
|
---|
108 | cat /tmp/command | ssh -o ConnectTimeout=3 -o BatchMode=yes root@$HOST 'cat >/tmp/command && sh /tmp/command'
|
---|
109 | } 1>$stdout_file 2>$stderr_file &
|
---|
110 | else
|
---|
111 | if [ -n "$scp_files" ]; then
|
---|
112 | scp -o ConnectTimeout=3 -o BatchMode=yes $scp_files root@$HOST:/tmp || exit 1
|
---|
113 | fi
|
---|
114 | cat /tmp/command | ssh -o ConnectTimeout=3 -o BatchMode=yes root@$HOST 'cat >/tmp/command && sh /tmp/command'
|
---|
115 | fi
|
---|
116 | done
|
---|
117 |
|
---|
118 | echo "# Wait for all processes to complete."
|
---|
119 | wait
|
---|