#!/bin/sh #efficiently upload logs from a list of ESP moorings #upload_top must be seeded with directories corresponding #to each ESP host from which upload. Each of these hostname #directories in turn should initially contain an empty directory #corresponing to each remote user whose log data is to be uploaded #parameters are the hostnames from which to upload #if none specified, default to ~ftp/ESP* #it is handy to name directories $upload_top/esp* for ethernet hostnames #while $upload_top/ESP* are symlinks to the corresponding radio hostnames . `dirname $0`/uploading.sh : ${upload_top:=`echo ~ftp`} cd $upload_top || exit $? : ${wget:="/usr/local/bin/wget -nv"} : ${upload_opts:="--progress=dot:binary -t 3 --connect-timeout=60 --retr-symlinks"} : ${upload_hosts:=${@:-ESP*}} url="ftp://" fetch() { #fetch $2 after changing directory to #1 cd $1 || exit $? local tmpFn=/tmp/upload.$$ uploading=$PWD/.UPLOADING.pid claim $uploading ($wget -N -c $upload_opts "$url$2$3" 2>&1 || { [ $? != 8 ] && echo -e "\nGiving up." }) | tee $tmpFn release $uploading grep -q "^Giving up." $tmpFn && { rm -f $tmpFn #stop uploading from this host if wget gave up return 1 } rm -f $tmpFn } uploadDirsOnly() { #upload only directories in the directory specified #$1 is the path part of the URL #recurse into any other directories already on the local destination local dir=$1 local item for item in $upload_top/$dir/*; do if [ -d "$item" ]; then cd $item || exit $? local path=$dir/`basename $item` fetch $item $path '/*' && uploadDirsOnly $path || return $? fi done } uploadDir() { #upload all items in the directory specified #$1 is the path part of the URL #recurse into any other directories already on the destination local dir=$1 local baseDir=$upload_top/$dir for item in $baseDir/*; do local path=$dir/`basename $item` if [ -d "$item" ]; then fetch $item $path '/*' && uploadDirsOnly $path || return $? else fetch $baseDir $path || return $? fi done } for ftpdir in $upload_hosts; do host=`basename $ftpdir` echo "Uploading from $host..." uploadDir $host && echo "*** $host Logs Synchronized ***" done