From 0eeeab14fc61d3de54e6a2f2d6567de75e719596 Mon Sep 17 00:00:00 2001 From: Matteo Cypriani Date: Mon, 20 May 2013 14:46:39 -0400 Subject: [PATCH] [cluster] Test the existence of the hosts' list We now test if the hosts' list file exists before to work on it. --- cluster/cluster-deploy.sh | 4 ++++ cluster/cluster-ping.sh | 8 +++++++- cluster/cluster-run.sh | 4 ++++ cluster/cluster-ssh.sh | 4 ++++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/cluster/cluster-deploy.sh b/cluster/cluster-deploy.sh index 4c11dc7..76aaee3 100755 --- a/cluster/cluster-deploy.sh +++ b/cluster/cluster-deploy.sh @@ -94,6 +94,10 @@ HOSTS_LIST_NAME="$1" HOSTS="$HOME/.config/cluster/${HOSTS_LIST_NAME}.lst" shift echo "Using file '$HOSTS' as hosts' list." +if [ ! -f "$HOSTS" ] ; then + echo "The hosts' list file doesn't exist or is not a regular file." + exit 3 +fi # Login if [ "$LOGIN" != "" ] ; then diff --git a/cluster/cluster-ping.sh b/cluster/cluster-ping.sh index e24d0c3..453b8b3 100755 --- a/cluster/cluster-ping.sh +++ b/cluster/cluster-ping.sh @@ -10,13 +10,19 @@ # # Ping a list of remote hosts using fping. +# Check arguments if [ $# -ne 1 ] ; then echo "Usage: $0 " exit 1 fi +# Hosts' list file HOSTS="$HOME/.config/cluster/$1.lst" -shift echo "Using file '$HOSTS' as hosts' list." +if [ ! -f "$HOSTS" ] ; then + echo "The hosts' list file doesn't exist or is not a regular file." + exit 2 +fi +# Go! exec fping $(cat "$HOSTS") 2>/dev/null diff --git a/cluster/cluster-run.sh b/cluster/cluster-run.sh index 673b6c0..d363599 100755 --- a/cluster/cluster-run.sh +++ b/cluster/cluster-run.sh @@ -47,6 +47,10 @@ fi HOSTS="$HOME/.config/cluster/$1.lst" shift echo "Using file '$HOSTS' as hosts' list." +if [ ! -f "$HOSTS" ] ; then + echo "The hosts' list file doesn't exist or is not a regular file." + exit 2 +fi # Login if [ "$LOGIN" != "" ] ; then diff --git a/cluster/cluster-ssh.sh b/cluster/cluster-ssh.sh index 0bcba94..9cf2e44 100755 --- a/cluster/cluster-ssh.sh +++ b/cluster/cluster-ssh.sh @@ -38,6 +38,10 @@ fi HOSTS="$HOME/.config/cluster/$1.lst" shift echo "Using file '$HOSTS' as hosts' list." +if [ ! -f "$HOSTS" ] ; then + echo "The hosts' list file doesn't exist or is not a regular file." + exit 2 +fi # Login if [ "$LOGIN" != "" ] ; then