在AIX下,想获取前几个月的时间,比较麻烦,不像Linux那样简单,上篇文档使用python实现了这个功能,今天花了半个小时,使用shell重写了该方法。
具体脚本如下:
#!/usr/bin/ksh
###############################################################################################################
#Script name: ./get_year_month.ksh
#Script description: drop table 3 months age.
#Current Release Version: 1.0.0
#Script Owner: hbhe0316
#Latest editor: hbhe0316
#Support platform: Linux OS for IBM AIX.
#Date: 2022/7/30---first Version for get_year_month.ksh
#Change log:
#Descript:./get_year_month.ksh
#
###############################################################################################################
month=$(date "+%m")
year=$(date "+%Y")
get_date_month(){
last_m=$((($year*12 + $month - $1 ) % 12 ))
last_y=$((($year*12 + $month - $1 ) / 12 ))
if [[ ${#last_m} -eq 1 ]];then
last_m=`echo $last_m | awk '{printf("%02d/n",$0)}'`
fi
year_month=$last_y$last_m
echo "year_month is $year_month"
}
main(){
get_date_month 190
}
main
版权声明:本文为博主原创文章,未经博主允许不得转载。
shell
- 上一篇:python获取前几个月的时间
- 下一篇:oracle 12c LREG