| 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 |
|
|---|
| 14 | ##
|
|---|
| 15 | ## Network differences
|
|---|
| 16 | ##
|
|---|
| 17 | #cat << 'EOF' >/tmp/command
|
|---|
| 18 | #sh -c ". /etc/rc.subr; load_rc_config "networking"; set" > /tmp/networking-env
|
|---|
| 19 | #grep -e ^ifconfig -e ^ipv4 /tmp/networking-env
|
|---|
| 20 | #{ grep -e ^ipv4 /tmp/networking-env | cut -d= -f2 | tr -d \' | xargs -n1 | cut -d/ -f1;
|
|---|
| 21 | # grep -e ^ifconfig /tmp/networking-env | grep -v -i 'dhcp' | cut -d= -f2 | tr -d \' | cut -d' ' -f2 | cut -d'/' -f1
|
|---|
| 22 | #} | sort -u > /tmp/config
|
|---|
| 23 | #ifconfig -a | grep 'inet ' | cut -d' ' -f2 | sort > /tmp/current
|
|---|
| 24 | #echo "# Comparing IP differences /tmp/current vs /tmp/config"
|
|---|
| 25 | #diff -u /tmp/current /tmp/config
|
|---|
| 26 | #EOF
|
|---|
| 27 |
|
|---|
| 28 | ##
|
|---|
| 29 | ## Migrate SSH authorized_keys symlink to new location.
|
|---|
| 30 | ##
|
|---|
| 31 | #cat <<'EOF' > /tmp/command
|
|---|
| 32 | #mount -uwo noatime / && unlink /root/.ssh && mkdir /root/.ssh && ln -s /etc/ssh/authorized_keys /root/.ssh/ && mount -ur
|
|---|
| 33 | #EOF
|
|---|
| 34 |
|
|---|
| 35 | ##
|
|---|
| 36 | ## View lvrouted configured flags and processes
|
|---|
| 37 | ##
|
|---|
| 38 | #cat <<'EOF' > /tmp/command
|
|---|
| 39 | #/usr/local/etc/rc.d/lvrouted rcvar | grep flags
|
|---|
| 40 | #pgrep -fl lvrouted
|
|---|
| 41 | #EOF
|
|---|
| 42 |
|
|---|
| 43 | ##
|
|---|
| 44 | ## Restart lvrouted
|
|---|
| 45 | ##
|
|---|
| 46 | #cat <<'EOF' > /tmp/command
|
|---|
| 47 | #sleep 30
|
|---|
| 48 | #nohup /usr/local/etc/rc.d/lvrouted restart
|
|---|
| 49 | #EOF
|
|---|
| 50 |
|
|---|
| 51 | ##
|
|---|
| 52 | ## Sync lvrouted and wl-config files
|
|---|
| 53 | ##
|
|---|
| 54 | #cat <<'EOF' > /tmp/command
|
|---|
| 55 | #mount -uwo noatime / || exit 1
|
|---|
| 56 | #trap "mount -ur /; exit 1" 1 2 3 15
|
|---|
| 57 | #trap "mount -ur /; exit 0" 0
|
|---|
| 58 | #
|
|---|
| 59 | #cp -v /tmp/wl-config /tools || exit 1
|
|---|
| 60 | #cp -v /tmp/lvrouted.in /usr/local/etc/rc.d/lvrouted || exit 1
|
|---|
| 61 | #cp -v /tmp/lvrouted.in /conf/base/etc/local/rc.d/lvrouted || exit 1
|
|---|
| 62 | #
|
|---|
| 63 | #/usr/local/etc/rc.d/lvrouted rcvar
|
|---|
| 64 | #EOF
|
|---|
| 65 |
|
|---|
| 66 | ##
|
|---|
| 67 | ## Run /tools/wl-config with random scheduler to avoid gold-rush and killing the
|
|---|
| 68 | ## config generator server
|
|---|
| 69 | ##
|
|---|
| 70 | #cat <<'EOF' > /tmp/command
|
|---|
| 71 | ##sleep `expr $$ % 120`
|
|---|
| 72 | #/tools/wl-config -b
|
|---|
| 73 | #EOF
|
|---|
| 74 |
|
|---|
| 75 | ##
|
|---|
| 76 | ## Detect routing loops and find out the actual default route
|
|---|
| 77 | ##
|
|---|
| 78 | ## Process output with:
|
|---|
| 79 | ## a) Proxy per host:
|
|---|
| 80 | ## 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
|
|---|
| 81 | ## b) Count per proxy:
|
|---|
| 82 | ## 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
|
|---|
| 83 | ##
|
|---|
| 84 | cat << 'EOF' > /tmp/command
|
|---|
| 85 | traceroute -m 15 -w 1 -q 1 -I rvdzwet.nl
|
|---|
| 86 | EOF
|
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 | # Cleanup old entries
|
|---|
| 90 | rm $PREFIX-* stderr-*
|
|---|
| 91 |
|
|---|
| 92 | for HOST in $HOSTS; do
|
|---|
| 93 | echo "# Working on $HOST"
|
|---|
| 94 | stdout_file="$PREFIX-${HOST%%.}.txt"
|
|---|
| 95 | stderr_file="stderr-${HOST%%.}.txt"
|
|---|
| 96 | : > $stdout_file
|
|---|
| 97 | : > $stderr_file
|
|---|
| 98 | {
|
|---|
| 99 | #scp -o ConnectTimeout=3 -o BatchMode=yes /tmp/wl-config /tmp/lvrouted.in root@$HOST:/tmp || exit 1
|
|---|
| 100 | cat /tmp/command | ssh -o ConnectTimeout=3 -o BatchMode=yes root@$HOST 'cat >/tmp/command && sh /tmp/command'
|
|---|
| 101 | } 1>$stdout_file 2>$stderr_file &
|
|---|
| 102 | done
|
|---|
| 103 |
|
|---|
| 104 | echo "# Wait for all processes to complete."
|
|---|
| 105 | wait
|
|---|