【发布时间】:2016-11-02 17:47:19
【问题描述】:
我有一个脚本可以找到任何用户密码的过期日期。脚本可以以秒(纪元)为单位找到过期日期,但无法将其转换为日期时间格式。
#!/usr/bin/ksh
if (( ${#} < 1 )) ; then
print "No Arguments"
exit
fi
lastupdate=`pwdadm -q $1|awk '{print $3;}'`
((lastupdate=$lastupdate+0))
maxagestr=`lsuser -a maxage $1`
maxage=${maxagestr#*=}
let maxageseconds=$maxage*604800
expdateseconds=$(expr "$maxageseconds" + "$lastupdate")
((expdateseconds=$expdateseconds+0))
expdate=`perl -le 'print scalar(localtime($expdateseconds))'`
echo $expdateseconds
echo $expdate
在此脚本中,expdateseconds 值为 true。如果我键入 expdateseconds 的值作为 localtime() 函数的参数,该函数会以 datetime 格式显示日期。
但是,如果我键入 $expdateseconds 变量,该函数将无法正常工作并始终返回 01.01.1970。
如何输入变量作为 localtime() 函数的参数?
【问题讨论】:
-
在你的
perl脚本周围使用 dbl 引号?另外,看看你的date命令提供了哪些选项,它是一个要加载的小程序(man date)。祝你好运。
标签: perl datetime ksh aix epoch