From: Colin P. Mccabe Date: Fri, 23 Feb 2018 22:18:56 +0000 (-0800) Subject: Add networkcanary.sh X-Git-Url: http://club.cc.cmu.edu/~cmccabe/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4920d97811487225e345ebd78a29d9e091ec7304;p=cmccabe-bin Add networkcanary.sh --- diff --git a/networkcanary.sh b/networkcanary.sh new file mode 100755 index 0000000..dfbaf57 --- /dev/null +++ b/networkcanary.sh @@ -0,0 +1,55 @@ +#!/usr/bin/env bash + +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +if [[ $# -lt 1 || $1 == "-h" || $1 == "--help" ]]; then + cat < /dev/tcp/$host/22" &> /dev/null + [[ $? -eq 0 ]] || echo "Failed to connect to port 22 on $host" + now=$(date +'%s') + rem=$((end-now)) + [[ $rem -gt 0 ]] && sleep -- $rem + done +} + +trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT +for host in $hosts; do + ping_host $host & +done + +wait