Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

#!/bin/bash
#### Directory variable####
LOG_DIR=’/data/logs/local_backup/’
HOST_NAME=`hostname -s`
LOG_LOCATION=’data/logs/something’
YYYY=`date +%Y`
MM=`date +%m –date=’1 month ago’`
FULL_PATH=$LOG_DIR$LOG_LOCATION
echo “$FULL_PATH”
for file in $FULL_PATH;do
file=`ls -d $FULL_PATH/*`
for i in $file; do
FINAL_PATH=$i/
mkdir -p $FINAL_PATH$YYYY/$MM
mv $FINAL_PATH*-$YYYY-$MM $FINAL_PATH$YYYY/$MM

done
done
#################

And if we need to add things like if it was last month of the year..
it would show as 12 and YYYY pointing to same year.

solution:

#!/bin/bash
#### Directory variable####
LOG_DIR=’/data/logs/local_backup/’
HOST_NAME=`hostname -s`
LOG_LOCATION=’data/logs/bidsys’
# YYYY=`date +%Y`
MM=`date +%m –date=’1 month ago’`
FULL_PATH=$LOG_DIR$LOG_LOCATION
echo “$FULL_PATH”
if [ “$MM” = “12” ]; then
echo “It was previous Year”
YYYY=`date +%Y –date=’1 year ago’`
echo “Now YYYY = $YYYY”
else
YYYY=`date +%Y`
fi
for file in $FULL_PATH;do
file=`ls -d $FULL_PATH/*`
for i in $file; do
FINAL_PATH=$i/
mkdir -p $FINAL_PATH$YYYY/$MM
mv $FINAL_PATH*-$YYYY-$MM $FINAL_PATH$YYYY/$MM

done
done