#!/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
Filter File By Time
原创emperor_majesty 博主文章分类:Shell ©著作权
©著作权归作者所有:来自51CTO博客作者emperor_majesty的原创作品,请联系作者获取转载授权,否则将追究法律责任
上一篇:lsnrctl security
下一篇:callout
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
小师妹学JavaIO之:File copy和File filter
一个linux命令的事情,小师
文件系统 nio java io 小师妹 -
CONTROL_FILE_RECORD_KEEP_TIME参数介绍
CONTROL_FILE_RECORD_KEEP_TIME参数介绍
控制文件 oracle CONTROL_FILE_RECORD_ -
使用logstash的input file filter收集日志文件
使用logstash的input file filter收集日志文件一、需求二、实现步骤1、前置知识2、编写piplugin 来实现。2、如何保证文件的每一行只读取一次? 这个是通过 sincedb来保证的。2、编写p
logstash logstash抓取本地日志 logstash file logstash 日志 logstash file日志