source: genesis/tools/batch-cmd@ 11701

Last change on this file since 11701 was 10985, checked in by rick, 13 years ago

Quirk to refresh all nameservers.

  • Property svn:executable set to *
File size: 3.9 KB
Line 
1#!/bin/sh
2#
3# Mega simple wrapper for batch control on nodes.
4#
5# Rick van der Zwet <rick@wirelessleiden.nl>
6#
7
8HOSTS=${*:-"`$(dirname $0)/gformat.py list up systems fqdn`"}
9PREFIX=${PREFIX:-'ip'}
10CMD=${CMD:-'md5 /usr/local/etc/rc.d/lvrouted'}
11
12echo "# WARN: Going to run at: " $HOSTS; sleep 2
13scp_files=""
14concurrent=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# Forcefully updating all the SOA records.
94cat << 'EOF' > /tmp/command
95rndc refresh wleiden.net
96rndc refresh 16.in-addr.arpa
97rndc refresh 17.in-addr.arpa
98rndc refresh 18.in-addr.arpa
99rndc refresh 19.in-addr.arpa
100rndc refresh 20.in-addr.arpa
101rndc refresh 21.in-addr.arpa
102rndc refresh 22.in-addr.arpa
103rndc refresh 23.in-addr.arpa
104rndc refresh 24.in-addr.arpa
105rndc refresh 25.in-addr.arpa
106rndc refresh 26.in-addr.arpa
107rndc refresh 27.in-addr.arpa
108rndc refresh 28.in-addr.arpa
109rndc refresh 29.in-addr.arpa
110rndc refresh 30.in-addr.arpa
111rndc refresh 31.in-addr.arpa
112EOF
113
114
115# Cleanup old entries
116rm $PREFIX-* stderr-*
117
118for HOST in $HOSTS; do
119 echo "# Working on $HOST"
120 stdout_file="$PREFIX-${HOST%%.}.txt"
121 stderr_file="stderr-${HOST%%.}.txt"
122 : > $stdout_file
123 : > $stderr_file
124 if $concurrent; then
125 {
126 if [ -n "$scp_files" ]; then
127 scp -o ConnectTimeout=3 -o BatchMode=yes $scp_files root@$HOST:/tmp || exit 1
128 fi
129 cat /tmp/command | ssh -o ConnectTimeout=3 -o BatchMode=yes root@$HOST 'cat >/tmp/command && sh /tmp/command'
130 } 1>$stdout_file 2>$stderr_file &
131 else
132 if [ -n "$scp_files" ]; then
133 scp -o ConnectTimeout=3 -o BatchMode=yes $scp_files root@$HOST:/tmp || exit 1
134 fi
135 cat /tmp/command | ssh -o ConnectTimeout=3 -o BatchMode=yes root@$HOST 'cat >/tmp/command && sh /tmp/command'
136 fi
137done
138
139echo "# Wait for all processes to complete."
140wait
Note: See TracBrowser for help on using the repository browser.