免费注册 查看新帖 |

Chinaunix

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

AIX ksh下如何将当前时间增1天 [复制链接]

论坛徽章:
1
天蝎座
日期:2014-05-08 23:48:07
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-07-27 16:31 |只看该作者 |倒序浏览
我的时间格式是yyyymmdd格式的,如20090727\r\n然后从文件中读取这个时间,文件名datefile\r\ndateflag=$(cat datefile)\r\n现在要将时间增1天,不可以用expr $dateflag + 1,这就变成整数相加了\r\n如何做,比如到月末的时候,会将月份也加1,天变成月第一天,谢谢指教!

论坛徽章:
0
2 [报告]
发表于 2009-07-27 20:08 |只看该作者
#!/usr/bin/ksh\r\n# step 1, generate application statistics at the morning for tomorrow\r\nget_one_day_after_specified_date()\r\n{\r\n#get the command line input(date month & year)\r\nday=$1\r\nmonth=$2\r\nyear=$3\r\n#use cal get the last day this month\r\nlastday=`cal $month $year | awk \'NF != 0{ last = $0 }; END{ print last }\' | awk \'{ print $NF }\'`\r\n# if it is the last day of the month\r\nif [ $day -eq $lastday ]\r\nthen\r\n# if it is the last month of the year\r\nif [ $month -eq 12 ]\r\nthen\r\n# make the month as 01\r\nmonth=01\r\n\r\n# add the year by one\r\nyear=`expr $year + 1`\r\nelse\r\n# add the month by one\r\nmonth=`expr $month + 1`\r\nfi\r\n\r\nday=01\r\nelse\r\n# add the day by one\r\nday=`expr $day + 1`\r\nfi\r\n \r\n echo $year$month$day\r\n\r\n}\r\n\r\nYEAR_T=`date +%Y`;\r\nMONTH_T=`date +%m`;\r\nDAY_T=`date +%d`;\r\n\r\nTOMORROW=`get_one_day_after_specified_date $DAY_T $MONTH_T $YEAR_T`;\r\necho $TOMORROW\n\n[ 本帖最后由 我老婆黑社会 于 2009-7-28 16:12 编辑 ]

论坛徽章:
0
3 [报告]
发表于 2009-07-27 20:09 |只看该作者
可以试试上面的脚本:wink:

论坛徽章:
1
操作系统版块每日发帖之星
日期:2016-08-11 06:20:00
4 [报告]
发表于 2009-07-28 10:23 |只看该作者
这样执行下,看行不?\r\nTZ=TZ+24   date\r\n\r\n要在一行执行,中间用空格,不能用分号

论坛徽章:
0
5 [报告]
发表于 2009-07-28 15:16 |只看该作者
1,是否没拷贝完全?少个{,\r\n2,怎样判断是月底?看不出来。

论坛徽章:
1
天蝎座
日期:2014-05-08 23:48:07
6 [报告]
发表于 2009-07-28 15:30 |只看该作者
我的aix使用date -d +1day竟然不行,-d选项它不认识,我在别的aix上就可以的,晕死!

论坛徽章:
0
7 [报告]
发表于 2009-07-28 16:46 |只看该作者
嗯,这个差不多!

论坛徽章:
1
天蝎座
日期:2014-05-08 23:48:07
8 [报告]
发表于 2009-07-28 21:54 |只看该作者
谢谢!目前用了个简单的办法,每天0点05分,自动写入时间
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP