#!/bin/sh -e # # sreget, Sat Oct 16 1999, Peter Csizmadia # prog=`basename $0` if [ $# -lt 1 ]; then cat << EOF $prog [login@]host:path [localfile] examples: $prog cspeter@sunserv:log/access_log $prog sunserv:log/access_log sunserv.log $prog sunserv:log/access_log sunserv.log.gz $prog sunserv:log/access_log sunserv.log.bz2 EOF exit 0 fi argn() { shift $1 ; echo $1 ; } loginhost="" path="" setloginhostpath() { if [ $# = 2 ]; then h=`echo $2 | sed 's/:/ /'` host=`argn 1 $h` path=`argn 2 $h` loginhost="-l $1 $host" else h=`echo $1 | sed 's/:/ /'` loginhost=`argn 1 $h` path=`argn 2 $h` fi } setloginhostpath `echo $1 | sed 's/@/ /'` if [ -z "$path" ]; then echo Remote file path not specified. >&2 exit 1 fi gzipped="n" bzipped="n" if [ $# -gt 1 ]; then localfile="$2" if [ -n "`echo $localfile | grep '\.gz$'`" ]; then if [ -z "`echo $path | grep '\.gz$'`" ]; then gzipped="y" echo -n "gunzipping: $localfile -> " >&2 gunzip "$localfile" localfile=`echo $localfile | sed 's/\.gz$//'` echo $localfile >&2 fi elif [ -n "`echo $localfile | grep '\.bz2'`" ]; then if [ -z "`echo $path | grep '\.bz2$'`" ]; then bzipped="y" echo -n "bunzipping: $localfile -> " >&2 bunzip2 "$localfile" localfile=`echo $localfile | sed 's/\.bz2$//'` echo $localfile >&2 fi fi else localfile=`basename $path` fi blocksize=1024 skip=0 if [ -f "$localfile" ]; then localsize=`ls -l $localfile` if [ "$?" = "0" ]; then localsize=`argn 5 $localsize` if [ "$localsize" != "0" ]; then blocksize=$localsize skip=1 fi fi fi ssh $loginhost "dd if=$path ibs=$blocksize skip=$skip | gzip -9"\ | gunzip >>$localfile if [ "$gzipped" = "y" ]; then echo -n "gzipping: $localfile -> " >&2 gzip -9 "$localfile" echo ${localfile}.gz >&2 fi if [ "$bzipped" = "y" ]; then echo -n "bzipping: $localfile -> " >&2 bzip2 "$localfile" echo ${localfile}.bz2 >&2 fi