[9947] | 1 | #!/bin/sh
|
---|
| 2 | #
|
---|
| 3 | # Mega simple wrapper for batch control on nodes.
|
---|
| 4 | #
|
---|
[10619] | 5 | # Rick van der Zwet <rick@wirelessleiden.nl>
|
---|
[9947] | 6 | #
|
---|
| 7 |
|
---|
[10619] | 8 | HOSTS=${*:-"`$(dirname $0)/gformat.py list up systems fqdn`"}
|
---|
[9947] | 9 | PREFIX=${PREFIX:-'ip'}
|
---|
[10619] | 10 | CMD=${CMD:-'md5 /usr/local/etc/rc.d/lvrouted'}
|
---|
[9947] | 11 |
|
---|
[10269] | 12 | echo "# WARN: Going to run at: " $HOSTS; sleep 2
|
---|
[10661] | 13 | scp_files=""
|
---|
| 14 | concurrent=true
|
---|
[9947] | 15 |
|
---|
[10632] | 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 | ##
|
---|
[10638] | 38 | ## View lvrouted configured flags and processes
|
---|
[10632] | 39 | ##
|
---|
[10634] | 40 | #cat <<'EOF' > /tmp/command
|
---|
[10632] | 41 | #/usr/local/etc/rc.d/lvrouted rcvar | grep flags
|
---|
[10638] | 42 | #pgrep -fl lvrouted
|
---|
[10634] | 43 | #EOF
|
---|
[10632] | 44 |
|
---|
[10634] | 45 | ##
|
---|
| 46 | ## Restart lvrouted
|
---|
| 47 | ##
|
---|
[10638] | 48 | #cat <<'EOF' > /tmp/command
|
---|
| 49 | #sleep 30
|
---|
| 50 | #nohup /usr/local/etc/rc.d/lvrouted restart
|
---|
| 51 | #EOF
|
---|
[10634] | 52 |
|
---|
| 53 | ##
|
---|
[10661] | 54 | ## Sync some files
|
---|
[10634] | 55 | ##
|
---|
[10661] | 56 | #scp_files="/tmp/wl-config /tmp/nameserver-shuffle"
|
---|
[10634] | 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
|
---|
[10632] | 61 | #
|
---|
[10634] | 62 | #cp -v /tmp/wl-config /tools || exit 1
|
---|
[10661] | 63 | #cp -v /tmp/nameserver-shuffle /tools || exit 1
|
---|
[10632] | 64 | #
|
---|
[10661] | 65 | #mount -ur / || exit 1
|
---|
| 66 | #/tools/wl-config -b || exit 1
|
---|
| 67 | #/tools/nameserver-shuffle || exit 1
|
---|
[10634] | 68 | #EOF
|
---|
[10632] | 69 |
|
---|
[10634] | 70 | ##
|
---|
| 71 | ## Run /tools/wl-config with random scheduler to avoid gold-rush and killing the
|
---|
| 72 | ## config generator server
|
---|
| 73 | ##
|
---|
[10985] | 74 | #cat <<'EOF' > /tmp/command
|
---|
| 75 | #sleep `expr $$ % 300`
|
---|
| 76 | #/tools/wl-config -b || exit 1
|
---|
| 77 | #/tools/nameserver-shuffle || exit 1
|
---|
| 78 | #EOF
|
---|
[10619] | 79 |
|
---|
[10638] | 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 | ##
|
---|
[10661] | 89 | #cat << 'EOF' > /tmp/command
|
---|
| 90 | #traceroute -m 15 -w 1 -q 1 -I rvdzwet.nl
|
---|
| 91 | #EOF
|
---|
[10632] | 92 |
|
---|
[10985] | 93 | # Forcefully updating all the SOA records.
|
---|
| 94 | cat << 'EOF' > /tmp/command
|
---|
| 95 | rndc refresh wleiden.net
|
---|
| 96 | rndc refresh 16.in-addr.arpa
|
---|
| 97 | rndc refresh 17.in-addr.arpa
|
---|
| 98 | rndc refresh 18.in-addr.arpa
|
---|
| 99 | rndc refresh 19.in-addr.arpa
|
---|
| 100 | rndc refresh 20.in-addr.arpa
|
---|
| 101 | rndc refresh 21.in-addr.arpa
|
---|
| 102 | rndc refresh 22.in-addr.arpa
|
---|
| 103 | rndc refresh 23.in-addr.arpa
|
---|
| 104 | rndc refresh 24.in-addr.arpa
|
---|
| 105 | rndc refresh 25.in-addr.arpa
|
---|
| 106 | rndc refresh 26.in-addr.arpa
|
---|
| 107 | rndc refresh 27.in-addr.arpa
|
---|
| 108 | rndc refresh 28.in-addr.arpa
|
---|
| 109 | rndc refresh 29.in-addr.arpa
|
---|
| 110 | rndc refresh 30.in-addr.arpa
|
---|
| 111 | rndc refresh 31.in-addr.arpa
|
---|
| 112 | EOF
|
---|
[10638] | 113 |
|
---|
[10985] | 114 |
|
---|
[10619] | 115 | # Cleanup old entries
|
---|
| 116 | rm $PREFIX-* stderr-*
|
---|
| 117 |
|
---|
[9947] | 118 | for HOST in $HOSTS; do
|
---|
[10634] | 119 | echo "# Working on $HOST"
|
---|
[10619] | 120 | stdout_file="$PREFIX-${HOST%%.}.txt"
|
---|
| 121 | stderr_file="stderr-${HOST%%.}.txt"
|
---|
| 122 | : > $stdout_file
|
---|
| 123 | : > $stderr_file
|
---|
[10661] | 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
|
---|
[10632] | 135 | cat /tmp/command | ssh -o ConnectTimeout=3 -o BatchMode=yes root@$HOST 'cat >/tmp/command && sh /tmp/command'
|
---|
[10661] | 136 | fi
|
---|
[9947] | 137 | done
|
---|
| 138 |
|
---|
[10619] | 139 | echo "# Wait for all processes to complete."
|
---|
[9947] | 140 | wait
|
---|