#!/bin/bash
+_ProdServers=" app1-1 app1-2 app2-1 app2-2 app3-1 app3-2 stanns bibc-prod"
+
usage()
{
cat <<EOF
-u Username to use when logging into remote server; if not provided, defaults to current user
-b Backup flag (optional); creates a backup instead of overwriting file on remote server
-h Print this message and exit
+ -P auto add all production machines to host list
EOF
}
-while getopts ":f:p:u:bh" opt
+while getopts ":f:p:u:bPh" opt
do
case $opt in
f ) FILE=$OPTARG;;
p ) DEST=$OPTARG;;
u ) USER=$OPTARG;;
b ) BACKUP="-b --suffix=.`date +%Y%m%d%H%M`";;
+ P ) PROD="P";;
h ) usage && exit 0;;
esac
done
shift $(($OPTIND - 1))
-if [[ -z "$FILE" ]] || [[ -z "$DEST" ]] | [[ $# -lt 1 ]]
+if [[ -z "$FILE" ]] || [[ -z "$DEST" ]] | ([[ $# -lt 1 ]] && [[ -z "$PROD" ]])
then
usage
exit 1
SSH="ssh -l${USER}"
fi
- for HOST in "$@"
+ if [[ -z "$PROD" ]]
+ then
+ _hosts="$@"
+ else
+ echo "adding ${_ProdServers} to hosts"
+ _hosts="$@$_ProdServers"
+ fi
+
+ for HOST in $_hosts
do
RSYNC_DEST="${HOST}:${DEST}"
#echo -e "$HOST:\n\tFILE=$FILE\n\tDEST=$DEST\n\tUSER=$USER\n\tBACKUP=$BACKUP\n\tSSH=$SSH\n\tRSYNC_DEST=$RSYNC_DEST\n"
--- /dev/null
+#!/bin/bash
+
+usage()
+{
+ cat <<EOF
+USAGE:
+./deployfile.sh -f filename -p /path/to/destination/ [ -u remoteuser ] [ -b ] host1 [ host2 ... ]
+
+OPTIONS:
+ -f Name of file to be deployed
+ -p Path on remote server where file should be deployed to
+ -u Username to use when logging into remote server; if not provided, defaults to current user
+ -b Backup flag (optional); creates a backup instead of overwriting file on remote server
+ -h Print this message and exit
+EOF
+}
+
+while getopts ":f:p:u:bh" opt
+do
+ case $opt in
+ f ) FILE=$OPTARG;;
+ p ) DEST=$OPTARG;;
+ u ) USER=$OPTARG;;
+ b ) BACKUP="-b --suffix=.`date +%Y%m%d%H%M`";;
+ h ) usage && exit 0;;
+ esac
+done
+shift $(($OPTIND - 1))
+
+if [[ -z "$FILE" ]] || [[ -z "$DEST" ]] | [[ $# -lt 1 ]]
+then
+ usage
+ exit 1
+else
+
+ if [[ -z "$BACKUP" ]]
+ then
+ SSH="ssh"
+ else
+ SSH="ssh -l${USER}"
+ fi
+
+ for HOST in "$@"
+ do
+ RSYNC_DEST="${HOST}:${DEST}"
+ #echo -e "$HOST:\n\tFILE=$FILE\n\tDEST=$DEST\n\tUSER=$USER\n\tBACKUP=$BACKUP\n\tSSH=$SSH\n\tRSYNC_DEST=$RSYNC_DEST\n"
+ rsync -e"${SSH}" $BACKUP -avz $FILE $RSYNC_DEST
+ done
+fi