in my shell scripts I need to rotate log directories. I am looking for a more compact, scaleable and elegant way than this, but have currently no idea how to solve this i.e. in a while loop and to calculate with variables.
function f_rotate_logdirs()
{
if [ -d $LOGDIR_OLD14 ]; then
# be extra cautious, no rm -rf operation ...
rm -rf $LOGDIR_OLD14
fi
if [ -d $LOGDIR_OLD13 ]; then
mv $LOGDIR_OLD13 $LOGDIR_OLD14
fi
[...]
if [ -d $LOGDIR_OLD1 ]; then
mv $LOGDIR_OLD1 $LOGDIR_OLD2
fi
if [ -d $LOGDIR ]; then
mv $LOGDIR $LOGDIR_OLD1
fi
mkdir -p $LOGDIR
echo $DATE > $LOGDIR/0.DATE
}
Do you have an idea for a more compact code which easily scales up to n_days ? Any help on this would be much appreachiated. Many thanks for this upfront.