uptimemon (1767B)
1 #!/bin/sh 2 # 3 # uptimemon.sh - monitor and record uptime (records) 4 # 5 # hayden@hhvn.uk 6 # Copyright (c) 2020 Hayden Hamilton 7 # 8 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 9 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 10 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 11 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 12 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 13 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 14 # SOFTWARE. 15 # 16 # This work is free. You can redistribute it and/or modify it under the 17 # terms of the Do What The Fuck You Want To Public License, Version 2, 18 # as published by Sam Hocevar. See http://www.wtfpl.net/ for more details. 19 20 d=$HOME/net/exec/uptime 21 22 #for s in matrix.hhvn.uk hhvn.uk irc1 irc2 dumbterm.hhvn.uk phony.hhvn.uk port.hhvn.uk mx1.hhvn.uk 23 for s in hhvn.uk irc1 irc2 dumbterm.hhvn.uk phony.hhvn.uk port.hhvn.uk mx1.hhvn.uk neutron.hhvn.uk 24 do 25 curr=$(ssh $s uptime | grep 'days' | awk '{print $3}' | grep '^[^:]*$' || echo 0) 26 ssh $s uptime >/dev/null && down=n || down=y # run the cmd again - variable can't be set 27 # in substitions 28 [ ! -f $d/$s ] && echo "curr $curr" > $d/$s 29 [ -f $d/$s ] && { 30 awk -F" " -v "curr=${curr:-0}" ' 31 $1 == "curr" { 32 if ($2 > curr) { 33 print "curr " curr 34 print "record " $2 35 } else { 36 print "curr " curr 37 } 38 } 39 $1 == "record"' < $d/$s > $d/$s.new 40 mv $d/$s.new $d/$s 41 [ "$down" = "y" ] && chmod +x $d/$s || chmod -x $d/$s # use executable perm to 42 # signal to uptime.dcgi 43 } 44 done