[linux-l] rsync: Abbruch bei grosser Datei

Frank Reker frank at reker.net
Di Jul 23 05:09:01 CEST 2019


Am Di 23. Jul 2019 02:55 +0200 schrieb Frank Reker:

>mkfifio /tmp/mypipe
>rsync [tralala] 2>&1 >> /tmp/mypipe | { tee -a $log2 & cat /tmp/mypipe; } | tee -a $log
>rm /tmp/mypipe

Hatte gerade Lust ein wenig zu scripten:
---begin myredirect----
#!/bin/bash

PROG="$(basename $0)"

die()
{
	ret=${1:-1}
	shift
	echo "$PROG: error $ret: $@" >&2
	exit $ret
}


SOPTS="hl:e:na"
LOPTS="help,log:,errlog:,noscreenout,noout,append"

TEMP="$(getopt -o "$SOPTS" --long "$LOPTS" -n "$PROG" -- "$@" || die $? error in getopt)"

eval set -- "$TEMP"

usage()
{
	cat << .
$PROG: usage: $PROG [<opts>...] -- <command> <args>
        <command>    - the command to execute
        <args>       - arguments passed to command
    <opts> are: 
        -h           - this help screen
        -l | --log <logfile>
                     - common logfile for stdout and stderr
        -e | --errlog <logfile>
                     - additional logfile for stderr only
        -n | --noscreenout | --noout
                     - do not write stdout/stderr to screen
        -a | --append
                     - appends to logfile instead of overwriting
                       applies to log and errlog
>.
}

while test "$1"; do
	case "$1" in
	-h|--help)
		usage
		exit 0
		;;
	-l|--log)
		log="$2"
		shift
		;;
	-e|--errlog)
		errlog="$2"
		shift
		;;
	-n|--noscreenout|--noout)
		noscreenout=yes
		;;
	-a|--append)
		append="-a"
		;;
	--)
		shift
		break
		;;
	esac
	shift
done

test "$1" || die 2 no command specified


dolog()
{
	if test "$log"; then
		tee $append "$log"
	else
		cat
	fi | \
	if test "$noscreenout"; then
		cat > /dev/null
	else
		cat
	fi
}

diecmd()
{
	die $? error excuting command: $@
}

if ! test "$errlog"; then
	{ $@ 2>&1 || diecmd $@; } | dolog
	exit 0
fi

tdir="$(mktemp -d /tmp/mypipe.XXXXXX)"
trap "rm -Rf $tdir" EXIT

mypipe="${tdir}/mypipe"

mkfifo "$mypipe" || die 3 cannot create named pipe $mypipe

{ $@ 2>&1 >> "$mypipe" || diecmd $@; } | \
	{ tee $append "$errlog" & cat "$mypipe"; } | dolog


exit 0

---end myredirect---

kannst du jetzt aufrufen mit:

myredirect -l $log -e $log2 -- rsync [tralala]
oder ohne screen ausgabe:
myredirect -l $log -e $log2 -n -- rsync [tralala]

ein zusaetzlichen -a haengt an die logfiles an anstatt sie zu
ueberschreiben:
myredirect -h funzt auch

viel Spass!



-- 
Don't worry be happy ...
Ciao Frank Reker



Mehr Informationen über die Mailingliste linux-l