# !/bin/bash # Copy a file to UFS-910 using ftp # Version 0.0.1 2009-01-02 # # Jochen Arndt # IP address of UFS-910. May be exported by calling script. test -z "$UFS_IP" && UFS_IP="192.168.178.19" # Default destination directory DEF_DESTDIR="/data" # Use "-v" to be verbose or "" to be not verbose #VERBOSE="" VERBOSE="-v" FTP=`which ftp` if [ "$FTP" = "" ]; then echo "Error: ftp program not found." exit 1 fi usage() { echo "Usage: $0 [-c] [-i ] [ []]" echo " -c = change file mode to 755 after copying" echo " -i ip = IP address of UFS-910 (default is 192.168.178.19)" echo " file-name = file to be copied" echo " dest-dir = destination directory (/data by default)" echo " dest-file = file name on target (basename of file-name by default)" } CHMOD="" SRCFILE="" DESTDIR="" DESTNAME="" while [ "$1" != "" ]; do case "$1" in -c | --chmod) CHMOD="yes" ;; -d | --destdir) shift DESTDIR="" ;; -h | --help) usage exit 0 ;; -i | --ip-address) shift UFS_IP="$1" ;; -q | --quiet) VERBOSE="" ;; -r | --rename) shift DESTNAME="" ;; -v | --verbose) VERBOSE="-v" ;; *) if [ -z "$SRCFILE" ]; then SRCFILE="$1" else if [ -z "$DESTDIR" ]; then DESTDIR="$1" else DESTNAME="$1" fi fi ;; esac shift done if [ -z "$SRCFILE" ]; then usage exit 1 fi if [ ! -e "$SRCFILE" ]; then echo "Error: File '$SRCFILE' not found." exit 1 fi if [ ! -f "$SRCFILE" ]; then echo "Error: '$SRCFILE' is not a file." exit 1 fi PING_OUT=`ping -c1 -q $UFS_IP` if [ $? -ne 0 ]; then # echo "$PING_OUT" echo "UFS does not respond on $UFS_IP" exit 1 fi # Default name and path on destination host test -z "$DESTNAME" && DESTNAME=`basename $SRCFILE` test -z "$DESTDIR" && DESTDIR="$DEF_DESTDIR" test -n "$CHMOD" && CHMOD="chmod 755 $DESTNAME" "$FTP" "$VERBOSE" -u -n "$UFS_IP" <<-EOF user root kathrein binary cd $DESTDIR put $SRCFILE $DESTNAME $CHMOD quit EOF