All pastes #974095 Raw Edit

HA

public shellscript v1 · immutable
·published 2008-04-06 15:42 UTC
rendered paste body
%   #!/bin/sh%%   export curdate=`date +%d%m%y`%   export reject=`date +%d`Many /bin/sh shells do *not* support the bash-extension of setting avariable and exporting it at the same time.The date arguments are not quoted properly.  In this case, it's probablygoing to work, but it's safer to use quotes.    curdate=` date '+%d%m%y' `    export curdate    reject=` date '+%d' `    export reject%   mount /log-stale%   cd /log-stale%   mkdir HOSTS%   cd /log-stale/HOSTSNo error-checking :(I'd probably start with something like:    err()    {        errcode="$1"        shift        if test -z "${errcode}" ; then            errcode=1        fi    }and use it every time an operation fails:    stalelogdir="/log-stale"    hostdir="${stalelogdir}/HOSTS"    mount "${stalelogdir}"    if test $? -ne 0 ; then        err 1 "${stalelogdir}: cannot mount"    fi    if test ! -d "${hostdir}" ; then        mkdir -p "${hostdir}"        if test $? -ne 0 ; then            umount "${stalelogdir}"            err 1 "${hostdir}: cannot create directory"        fi    fi%   for i in ls /log-fresh/HOSTS/*/*/*/ ; do if [[ ls $i != /log-fresh/HOSTS/*/*/reject ]]; then mv $i /log-stale/HOSTS/ fi ; doneIndentation is 90% of the readability of a source file.  Please wraplines to a more reasonable length.Another tricky point here is that if there are too many matches in thefilename wildcard, you will hit command-line limits.  It's usuallybetter to feed filenames one by one to a reader loop:    find /log-fresh/HOSTS -type d | \    while read dname ; do        # Perform something in directory "${dname}"    done%   tar -cf logs_$curdate.tar /log-stale/HOSTS/%   bzip2 logs_$curdate.tar%   rm -rf /log-stale/HOSTS/%   cd /%   umount /log-stale%   exit 0No error checking here either :(