Showing posts with label logrotate. Show all posts
Showing posts with label logrotate. Show all posts

Monday, 10 April 2017

simple bash 'logrotate'

'logrotate' = not a logrotate but more of a multiple result handle
e.g. test results, core files, log files

'infinate' (max bash integer) 'logrotate' pattern for bash:


    # multiple runs of same test, . . logrotate test result
    [[ -e dir/testresult_${testname}_${host}.xml ]] && {
        K=$(find dir/testresult_${testname}_*_${host}.xml 2>/dev/null |wc -l)
        ((K++))
        mv dir/testresult_${testname}_{,${K}_}${host}.xml
    }

Coupled with test harvest e.g. . . 
rsync -avzh --remove-source-files ${user}@${host}:XML/*${host}.xml ./ || true

optional || true so that lack of xml files doesn't mark job/script as fail


Wednesday, 17 February 2010

bash shell logrotate function

# Yet Another installation in the Yet Another script to do whatever series

# I have done logrotate in bash in at least two other flavours before. :-7

# bash shell logrotate function
function logroti () {
for f in $* ; do
echo logroti for f
if [ -e "$f" ] ; then
ROTFILES=$(find $f.[0-9] 2>/dev/null| sort -r )
for rf in $ROTFILES; do
BASE=${rf%.*}
NUM=${rf##$BASE.}
((NUM++))
echo logroti for rf=$rf BASE=$BASE NUM=$NUM new file $BASE.$NUM
mv -f $rf $BASE.$NUM
done
cp -f $f $f.0
cat /dev/null > $f
fi
done
}

# e.g. usage
logroti run_demo.log
while [ 1 ]; do
logrotate demo.log 2>&1 |tee -a run_demo.log
date |tee -a run_demo.log
echo "DEMO script start" |tee -a run_demo.log
tclsh RunDemo.tcl 2>&1 |tee demo.log
date |tee -a run_demo.log
echo "DEMO script exited" |tee -a run_demo.log
done

# the tcl script internally at top level has a catch {...} sError
# but some errors get past this! :)
# So am catching everything and can see how long things run for and what errors cause any problems