使用ksh在HP-UX中过滤日期 [英] Getting past dates in HP-UX with ksh

查看:138
本文介绍了使用ksh在HP-UX中过滤日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,所以我需要从一个漂亮的linux& bash配置到hp-ux中的ksh。每个命令都希望使用不同的语法,我想杀死自己。但是让我们跳过这个咆哮。



这是我脚本的一部分

 前面=`date +'%Y%0m-d'1个月前'

基本上需要以201002格式获取过去的日期。不要在新的环境中,%0m表示没有零,而在另一个实际上它意味着是的,请把这个零我的字符串。它甚至不接受1个月前。我已经阅读了HP-UX的日期,似乎你根本无法对其进行日期算术。



我一直在寻找一段时间,我找到的都是冗长的解决方案。我不太明白,这样一个典型的管理任务,比如添加日期,需要非常大的麻烦。是不是有办法把我的一线转换成好,我不知道,另一个?来吧,我已经看到提出使用bc的解决方案,在脚本中有三十加线和魔术数字。最简单的解决方案似乎使用perl ...但是我不知道如何修改它们,因为它们非常神秘。



谢谢!

解决方案

这是我来的解决方案(警告:我正在一个客户端进行恶劣的安全措施,所以我甚至没有方式来测试它,我需要发送我的脚本到系统管理员来测试他们并通过他调试)。

  typeset -Z2 lastmonth 
month =`date +%m`
year =`date +%Y`

lastmonth = $((month-1))
if(( month == 1));然后
lastmonth = 12
year = $((year-1))
fi

无论如何,它使我觉得没有更简单的方法来实现。


Ok, so I need to translate a script from a nice linux & bash configuration to ksh in hp-ux. Each and every command expects a different syntax and i want to kill myself. But let's skip the rant.

This is part of my script

anterior=`date +"%Y%0m" -d '1 month ago'`

I basically need to get a past date in format 201002. Never mind the thing that, in the new environment, %0m means "no zeroes", while actually in the other one it means "yes, please put that zero on my string". It doesn't even accept the "1 month ago". I've read the man date for HP-UX and it seems you just can't do date arithmetic with it.

I've been looking around for a while but all i find are lengthy solutions. I can't quite understand that such a typical administrative task like adding dates needs so much fuss. Isn't there a way to convert my one-liner to, well, i don't know, another one? Come on, i've seen proposed solutions that used bc, had thirty plus lines and magic number all over the script. The simplest solutions seem to use perl... but i don't know how to modify them, as they're quite arcane.

Thanks!

解决方案

This is the solution I came to (warning: I'm working at a client with draconian security measures, so i don't even have a way to test it, i need to send my scripts to a sysadmin to test them and debug through him).

typeset -Z2 lastmonth
month=`date +%m`
year=`date +%Y`

lastmonth=$((month-1))
if (( month == 1));then
lastmonth=12
year=$((year-1))
fi

Anyway, it strikes me that there is no simpler way to do that.

这篇关于使用ksh在HP-UX中过滤日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆