[cluster] Give up using getopt

getopt prevents using spaces in the arguments.
This commit is contained in:
Matteo Cypriani 2013-05-02 10:56:28 -04:00
parent 97b1630fc8
commit 3226138f25
3 changed files with 42 additions and 84 deletions

View File

@ -9,43 +9,30 @@
# http://sam.zoy.org/wtfpl/COPYING for more details.
#
# Deploy files on a number of remote hosts using Parallel SCP.
#set -x
print_usage()
{
echo "Usage: $0 [-l login] <hosts_list> <file1> [file2 [...]]"
}
# Parse the optional arguments with getopt
export POSIXLY_CORRECT=yes
export GETOPT_COMPATIBLE=yes
OPTSTRING="l:"
ARGS=$(getopt $OPTSTRING $*)
if [ $? -ne 0 ] ; then
# Do we have at least a host list and a file?
if [ $# -lt 2 ] ; then
print_usage
exit 1
fi
set -- $ARGS
while [ $# -ne 0 ] ; do
case "$1" in
-l)
LOGIN="$2"
shift
shift
;;
--)
shift
break
;;
*)
echo "Unknown argument:" $1
exit 2
esac
done
# Do we have at least a host list and a command?
if [ $# -lt 2 ] ; then
print_usage
exit 3
# Parse the optional arguments
if [ "$1" = "-l" ] ; then
LOGIN="$2"
shift
shift
# Do we still have at least a host list and a file?
if [ $# -lt 2 ] ; then
print_usage
exit 3
fi
fi
# Check dependencies
@ -66,7 +53,7 @@ if [ "$LOGIN" != "" ] ; then
LOGIN="-l $LOGIN"
fi
for FILE in $@ ; do
for FILE in "$@" ; do
echo "Deploying '$FILE'..."
$PSCP -r $LOGIN -h "$HOSTS" -- "$FILE" /root
done

View File

@ -17,37 +17,23 @@ print_usage()
echo "Usage: $0 [-l login] <hosts_list> <command>"
}
# Parse the optional arguments with getopt
export POSIXLY_CORRECT=yes
export GETOPT_COMPATIBLE=yes
OPTSTRING="l:"
ARGS=$(getopt $OPTSTRING $*)
if [ $? -ne 0 ] ; then
print_usage
exit 1
fi
set -- $ARGS
while [ $# -ne 0 ] ; do
case "$1" in
-l)
LOGIN="$2"
shift
shift
;;
--)
shift
break
;;
*)
echo "Unknown argument:" $1
exit 2
esac
done
# Do we have at least a host list and a command?
if [ $# -lt 2 ] ; then
print_usage
exit 3
exit 1
fi
# Parse the optional arguments
if [ "$1" = "-l" ] ; then
LOGIN="$2"
shift
shift
# Do we still have at least a host list and a command?
if [ $# -lt 2 ] ; then
print_usage
exit 3
fi
fi
# Check dependencies

View File

@ -16,35 +16,20 @@ print_usage()
echo "Usage: $0 [-l login] <hosts_list>"
}
# Parse the optional arguments with getopt
export POSIXLY_CORRECT=yes
export GETOPT_COMPATIBLE=yes
OPTSTRING="l:"
ARGS=$(getopt $OPTSTRING $*)
if [ $? -ne 0 ] ; then
print_usage
exit 1
fi
set -- $ARGS
while [ $# -ne 0 ] ; do
case "$1" in
-l)
LOGIN="$2"
shift
shift
;;
--)
shift
break
;;
*)
echo "Unknown argument:" $1
exit 2
esac
done
# We must have either 3 arguments...
if [ $# -eq 3 ] ; then
# Parse the optional arguments
if [ "$1" = "-l" ] ; then
LOGIN="$2"
shift
shift
else # Option unknown
print_usage
exit 1
fi
# Do we have only one argument left?
if [ $# -ne 1 ] ; then
# ... or only 1
elif [ $# -ne 1 ] ; then
print_usage
exit 3
fi