#!/bin/bash
#set -x
#you could chang the inpath and outpath arbitrarily.
#filter the file to a assign directory ,according to the time.
inpath=/root/Desktop
mkdir -p /home/oracle/store
outpath=/home/oracle/store

ls --full-time -lt $inpath   > /tmp/input_allfiles_info.txt
var=`cat /tmp/input_allfiles_info.txt | grep -v ^total`
while read input
do
   echo $input > /tmp/tmp01.txt
   tmp_name=`cat /tmp/tmp01.txt  | awk '{print $9}'`
   tmp_second=`cat /tmp/tmp01.txt| cut -f3 -d':' | cut -f1 -d'.' | awk '{print $1}'`
   tmp_minute=`cat /tmp/tmp01.txt| cut -f2 -d':' | awk '{print $1}'`
   tmp_hour=`cat /tmp/tmp01.txt  | cut -f1 -d':' | awk '{print $7}'`
   tmp_day=`cat /tmp/tmp01.txt   | cut -f2 -d'.' | cut -f3 -d'-' | awk '{print $1}'`
   tmp_month=`cat /tmp/tmp01.txt | cut -f2 -d'.' | cut -f2 -d'-' | awk '{print $1}'`
   tmp_year=`cat /tmp/tmp01.txt  | cut -f2 -d'.' | cut -f1 -d'-' | awk '{print $5}'`

#year
for c1 in 2012; do
   [ $tmp_year == $c1 ] && newpath1=$outpath/$c1; 
done

#month
for c2 in 00 01 02 03 04 05 06 07 08 09 10 11 12;do
   [ $tmp_month == $c2 ] && newpath2=$newpath1/$c2
done

#day
for c3 in 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31; do
   [ $tmp_day == $c3 ] && newpath3=$newpath2/$c3
done

#hour
for c4 in 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23; do
   [ $tmp_hour == $c4 ] && newpath4=$newpath3/$c4
done

case $tmp_minute in
00) tmp_minute=0 ;;
01) tmp_minute=1 ;;
02) tmp_minute=2 ;;
03) tmp_minute=3 ;;
04) tmp_minute=4 ;;
05) tmp_minute=5 ;;
06) tmp_minute=6 ;;
07) tmp_minute=7 ;;
08) tmp_minute=8 ;;
09) tmp_minute=9 ;;
*)  export nochange=1 ;;
esac

#minute locate here
if [ -d $inpath/$tmp_name ];then
   echo "The shell do not support dirctory file!! skip..... "
else
 if   [ $tmp_minute -ge 0  -a $tmp_minute -le 10  ];then
     mkdir -p $newpath4/0-10
     cp  $inpath/$tmp_name $newpath4/0-10 &>/dev/null
 elif [ $tmp_minute -ge 11 -a $tmp_minute -le 20  ];then
     mkdir -p $newpath4/11-20
     cp  $inpath/$tmp_name $newpath4/11-20 &>/dev/null
 elif [ $tmp_minute -ge 21 -a $tmp_minute -le 30  ];then
     mkdir -p $newpath4/21-30
     cp  $inpath/$tmp_name $newpath4/21-30 &>/dev/null
 elif [ $tmp_minute -ge 31 -a $tmp_minute -le 40  ];then
     mkdir -p $newpath4/31-40
     cp  $inpath/$tmp_name $newpath4/31-40 &>/dev/null
 elif [ $tmp_minute -ge 41 -a $tmp_minute -le 50  ];then
     mkdir -p $newpath4/41-50
     cp  $inpath/$tmp_name $newpath4/41-50 &>/dev/null
 elif [ $tmp_minute -ge 51 -a $tmp_minute -le 60  ];then
     mkdir -p $newpath4/51-60
     cp  $inpath/$tmp_name $newpath4/51-60
 else export end=1
 fi
fi
done<<EOF
$var
EOF