免费注册 查看新帖 |

Chinaunix

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

新手求助:如何在HP-UX下获得前一日的日期 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-06-14 00:09 |只看该作者 |倒序浏览
date +\'%m%d\'  可以取到当前日期,格式为mmdd

但是我现在需要得到昨天的日期,格式仍为mmdd,请教高手如何实现?

一定需要写shell才能实现的么?

论坛徽章:
0
2 [报告]
发表于 2006-06-14 09:13 |只看该作者
贴出我的代码的一部分

  1. # step 1, generate application statistics at the morning for yesterday
  2. get_one_day_before_specified_date()
  3. {
  4. #get the command line input(date month & year)
  5.     day=$1
  6.     month=$2
  7.     year=$3

  8.     # if it is the first day of the month
  9.     if [ $day -eq 01 ]
  10.     then
  11.         # if it is the first month of the year
  12.         if [ $month -eq 01 ]
  13.         then
  14.             # make the month as 12
  15.             month=12

  16.             # deduct the year by one
  17.             year=`expr $year - 1`
  18.         else
  19.             # deduct the month by one
  20.             month=`expr $month - 1`
  21.         fi
  22.          
  23.         # use cal command, discard blank lines,
  24.         # take last field of last line,   
  25.         # first awk  command is used to get the
  26.         # last useful line of the calendar cmd,
  27.         # second awk command is used to get the   
  28.         # last field of this last useful line,
  29.         # NF is no. of fields,
  30.         # $NF is value of last field

  31.                 day=`cal $month $year | awk \'NF != 0{ last = $0 }; END{ print last }\' |  awk \'{ print $NF }\'`
  32.     else
  33.         # deduct the day by one
  34.         day=`expr $day - 1`
  35.     fi

  36.     # echo $month $day $year
  37.     year_2dig=`echo $year|awk \'{print substr($0,3)}\'`
  38.     echo $month/$day/$year_2dig
  39. }

  40. YEAR_T=`date +%Y`;
  41. MONTH_T=`date +%m`;
  42. DAY_T=`date +%d`;

  43. YESTERDAY=`get_one_day_before_specified_date $DAY_T $MONTH_T $YEAR_T`;

  44. # echo \"===============${YESTERDAY}==================\";
复制代码

论坛徽章:
0
3 [报告]
发表于 2006-06-15 12:49 |只看该作者
多些,我的主机也是11的。怎么说是贴出代码的一部分,难道还有下文?
先试试看了。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP