- 论坛徽章:
- 0
|
本帖最后由 sxtywyg 于 2012-06-20 14:48 编辑
personball 发表于 2012-06-20 14:27
回复 1# sxtywyg
谢谢
再详细描述一下我的需求:
我现在制作了一个菜单化脚本,要获取日志,日志目录下存在大量的日志文件,我想通过获取某个时间段,来自动化获取日志并FTP,下面是部分代码
echo -e -n "\t请选择 [1,Q]>"
read choice2
case $choice2 in
1) while :
do
echo -e "\t请输入所需日志起始时间:<YYYY-MM-DD HH:MM>"
read date1
if [[ "$date1" != [0-9]{4}-[0-9]{1,2}-[0-9]{1,2}\ [0-9]{2}:[0-9]{2} ]]; (这个就没起作用)
then
read date1 (无论输入什么日期,都返回"请输入所需日志起始时间",无法执行下面的代码)
else
touch -d "$date1" /root/file1
fi
done
while :
do
echo -e "\t请输入所需日志结束时间:<YYYY-MM-DD HH:MM>"
read date2
if [[ "$date2" != [0-9]\{4}-[0-9]{1,2}-[0-9]{1,2}\ [0-9]{2}:[0-9]{2} ]];
then
read date2
else
touch -d "$date2" /root/file2
fi
done
find /root -newer file1 -a ! -newer file2 -a -type f -print | xargs ls -alt | grep -v ^d
while :
do
echo -e -n "\t请选择需要的日志:"
read log
cd /root
if [ -f $log ];then
cp $log /tmp/bak
cd /tmp/bak
tar -cvf bak.tar /tmp/bak/*
rm -rf $log
get_myserver_nohup.out (这个是定义可以FTP的函数)
echo -e "\t上传成功\n"
exit 0
else
echo -e "\tFault Choice"
fi
done
;;
我上面开始提问的脚本,是我单独想实现我描述的两个功能,
如果按照你说的,使用date -d格式化输出日期的话,是不是会有问题?我的理由是:
find /root -newer file1 -a ! -newer file2 -a -type f -print | xargs ls -alt | grep -v ^d
这个发现的日志是按照系统格式的时间输出,模式的时间格式好象是YYYY-MM-DD HH:MM:SS (不过我这里不需要秒了,有分钟就足够了) |
|