This is my script :
set -x
PTH=/data0101/track_logs
cd /data0101/track_logs
if [[ `ls -lrth | grep IMEI_TRACK | wc -l` -gt 0 ]];
then
FILE_COUNT=`ls -lrth | grep IMEI_TRACK | wc -l`
YEAR=`date | awk '{print $6}'`
mkdir $PTH/$YEAR
MONTH=`date | awk '{print $2}'`
mkdir $PTH/$YEAR/$MONTH
DAY=`date | awk '{print $3}'`
HOUR=`date | awk '{print $4}' | cut -d":" -f 1`
if [[ $HOUR -ne 0 ]];
then
HR=$(( $HOUR - 1 ))
else
DAY=$(( $DAY - 1 ))
HR=23
mkdir $PTH/$YEAR/$MONTH/$DAY
fi
case $HR in
00-23) for (( i=1;i<=$FILE_COUNT;i++ ))
do
chk=`ls -lrth | grep IMEI_TRACK | head -$i | tail -1 | awk '{print $8}' | cut -d: -f1`
FILE=`ls -lrth | grep IMEI_TRACK | awk '{print $9}'`
if [[ $chk -eq $HR ]];
then
mkdir $PTH/$YEAR/$MONTH/$DAY/$HR
mv $FILE $PTH/$YEAR/$MONTH/$DAY/$HR/
else
break
fi
done ;;
esac
fi
When I run the script this is what I get:
+ PTH=/data0101/track_logs
+ cd /data0101/track_logs
++ ls -lrth
++ grep IMEI_TRACK
++ wc -l
+ [[ 200 -gt 0 ]]
++ ls -lrth
++ grep IMEI_TRACK
++ wc -l
+ FILE_COUNT=200
++ date
++ awk '{print $6}'
+ YEAR=2012
+ mkdir /data0101/track_logs/2012
mkdir: cannot create directory `/data0101/track_logs/2012': File exists
++ date
++ awk '{print $2}'
+ MONTH=Dec
+ mkdir /data0101/track_logs/2012/Dec
mkdir: cannot create directory `/data0101/track_logs/2012/Dec': File exists
++ date
++ awk '{print $3}'
+ DAY=20
++ date
++ awk '{print $4}'
++ cut -d: -f 1
+ HOUR=14
+ [[ 14 -ne 0 ]]
+ HR=13
+ case $HR in
This clearly shows that this script is not getting further than the case statement. Is there anything wrong with my case construct. Kindly help. Also suggestions on overall development of the script is also welcome.
I tried using the range in my case construct like this:
case $HR in
[00-23]) for (( i=1;i<=$FILE_COUNT;i++ ))
do
chk=`ls -lrth | grep IMEI_TRACK | head -$i | tail -1 | awk '{print $8}' | cut -d: -f1`
FILE=`ls -lrth | grep IMEI_TRACK | awk '{print $9}'`
if [[ $chk -eq $HR ]];
then
mkdir $PTH/$YEAR/$MONTH/$DAY/$HR
mv $FILE $PTH/$YEAR/$MONTH/$DAY/$HR/
else
break
fi
done ;;
esac
bu this doesn't help as well.