Chinaunix

标题: 问一个循环设置日期的问题 [打印本页]

作者: mmh    时间: 2008-11-05 11:06
标题: 问一个循环设置日期的问题
如现在的时间是20081105,现在想把时间设置成每减去一天设置一下日期然后执行一个命令。
例如:date -s 20081104 ls
          date -s 20081103 ls
                  .........
           date -s 前60天
作者: davistar    时间: 2008-11-05 11:14

  1. for((i=1;i<=60;i++));do echo "date -s $(date +%Y%m%d -d "-$i day");ls";done
复制代码

作者: mmh    时间: 2008-11-05 11:17
for((i=1;i<=60;i++));do date -s `date -d "-$i day" +%Y%m%d`  ls; done
我是这么写的为什么就直接设到2003年去了

for((i=1;i<=60;i++));do echo "date -s $(date +%Y%m%d -d "-$i day");ls";done
你这个就是可以的?  
没搞明白
作者: mmh    时间: 2008-11-05 11:25
不对哦 并不是要显示日期  日期要设置到系统上  因为我要执行的命令是要导入昨天的日志 而这个命令的执行是以系统日期为准的。
例如:现在是20081105 这个命令就行导入20081104的日志 在接着把系统日期设成20081104 导入20081103的日志
作者: davistar    时间: 2008-11-05 11:25
ls前面加个分号呢

我echo是因为我不想改我系统上的日期。。
作者: mmh    时间: 2008-11-05 11:34
for((i=1;i<=60;i++));do "date -s $(date +%Y%m%d -d "-$i day")";done
去掉echo的话就报错了,怎么会报这种错误?
-bash: date -s 20081104: command not found
-bash: date -s 20081103: command not found
-bash: date -s 20081102: command not found
-bash: date -s 20081101: command not found
-bash: date -s 20081031: command not found
-bash: date -s 20081030: command not found
-bash: date -s 20081029: command not found
-bash: date -s 20081028: command not found
-bash: date -s 20081027: command not found
-bash: date -s 20081026: command not found
-bash: date -s 20081025: command not found
-bash: date -s 20081024: command not found
-bash: date -s 20081023: command not found
-bash: date -s 20081022: command not found
作者: mmh    时间: 2008-11-05 12:47
为什么会出现这么错误呢,难到真的没有人干过这种事情???




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2