免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 8480 | 回复: 18
打印 上一主题 下一主题

求助:如何每天都取昨天的日期 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-05-08 15:40 |只看该作者 |倒序浏览
小弟初学。这个问题把我难住了

    我想每天都取昨天的日期。
    因为我的apache日志是按天用cronolog截断的
    格式是:/log/httpd/2005/05/08/access_log

      我要把今天把昨天的 access_log 考走。。

   请问 我该怎么用总是今天取昨天的日期阿?

论坛徽章:
1
荣誉会员
日期:2011-11-23 16:44:17
2 [报告]
发表于 2005-05-08 16:04 |只看该作者

求助:如何每天都取昨天的日期


  1. find /path -mtime 1 -exec cp {} /path \;
复制代码

取昨天日期的讨论搜索论坛

论坛徽章:
0
3 [报告]
发表于 2005-05-08 16:20 |只看该作者

求助:如何每天都取昨天的日期

寂寞烈火,你好,你说的代码“find /path -mtime 1 -exec cp {} /path \;”里的“{}”里什么都不填吗?这个大括号是什么用处?取文件的关键字吗?

论坛徽章:
1
荣誉会员
日期:2011-11-23 16:44:17
4 [报告]
发表于 2005-05-08 16:23 |只看该作者

求助:如何每天都取昨天的日期

[quote]原帖由 "xiaogang008"]寂寞烈火,你好,你说的代码“find /path -mtime 1 -exec cp {} /path \;”里的“{}”里什么都不填吗?这个大括号是什么用处?取文件的关键字吗?[/quote 发表:

这个{},用于存放find后的结果!
关于find,请参阅置顶shell基础十二篇,或者看他的手册

论坛徽章:
0
5 [报告]
发表于 2005-05-08 16:56 |只看该作者

求助:如何每天都取昨天的日期

Thanks.
    俺看了这个:
   #!/bin/bash
# Var Declare
#!/bin/sh
# ydate: A Bourne shell script that
# prints yestarday's date
# Output Form: Month Day Year
# From Focus on Unix: http://unix.about.com

# Set the current month day and year.
month=`date +%m`
day=`date +%d`
year=`date +%Y`

# Add 0 to month. This is a
# trick to make month an unpadded integer.
month=`expr $month + 0`

# Subtract one from the current day.
day=`expr $day - 1`

# If the day is 0 then determine the last
# day of the previous month.
if [ $day -eq 0 ]; then

# Find the preivous month.
month=`expr $month - 1`

# If the month is 0 then it is Dec 31 of
# the previous year.
if [ $month -eq 0 ]; then
   month=12
   day=31
   year=`expr $year - 1`

# If the month is not zero we need to find
# the last day of the month.
else
   case $month in
     1|3|5|7|8|10|12) day=31;;
     4|6|9|11) day=30;;
     2)
       if [ `expr $year % 4` -eq 0 ]; then
         if [ `expr $year % 400` -eq 0 ]; then
           day=29
       fi
       else
         day=28
       fi
     ;;
   esac
fi
fi

论坛徽章:
0
6 [报告]
发表于 2005-05-08 18:05 |只看该作者

求助:如何每天都取昨天的日期

上面的代码我也看过,但在csh下无法使用,csh环境不支持“[]”的使用,执行程序后提示Missing ],怎么解决啊?急啊!!

论坛徽章:
0
7 [报告]
发表于 2005-05-08 18:14 |只看该作者

求助:如何每天都取昨天的日期

如果linux
yesterday=$(date -d"yesterday" +%m%d)
如果是Solrais
yesterday=`TZ=$TZ+32 date +%m%d`

论坛徽章:
0
8 [报告]
发表于 2005-05-08 18:26 |只看该作者

求助:如何每天都取昨天的日期

原帖由 "fangjy2008" 发表:
如果linux
yesterday=$(date -d"yesterday" +%m%d)
如果是Solrais
yesterday=`TZ=$TZ+32 date +%m%d`



但是这样做好像修改了系统的时区时间,能否在不对系统的时间做任何修改的情况下操作?在csh下如何用if来判断?bsh可以用[],csh下如何使用呢?

论坛徽章:
0
9 [报告]
发表于 2005-05-08 19:44 |只看该作者

求助:如何每天都取昨天的日期

csh里可以用:
if (str1 == str2) then
echo ....
else
echo ....
endif

论坛徽章:
1
荣誉会员
日期:2011-11-23 16:44:17
10 [报告]
发表于 2005-05-08 23:03 |只看该作者

求助:如何每天都取昨天的日期

在所有的shell中,csh是最差的
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP