1、AIX 机器上定期清除日志文件,以释放日志文件所占用的大量磁盘空间。
shell似乎没有处理日期计算的函数,在JAVA中处理日期很方便,而SHELL处理日期太费劲,等于自己要写一个原始的日期加减函数。这里考虑特定的应用,在已有网友代码的基础上进行了一下改进,可以计算从当前日期起N天前的日期。KSH实现。
AIX 5.3 执行通过
#!/bin/ksh
LOG_PATH=/home/utan/logs
LOG_DEL_LOGFILE=./logdel.log
KEEP_DAYS=9
# Set the current month day and year.
month=`date +%m`
day=`date +%d`
year=`date +%Y`
#get the yesterday
getLastDay()
{
# Set the current month day and year.
# month=`date +%m`
# day=`date +%d`
# year=`date +%Y`
year=$1
month=$2
day=$3
# Add 0 to month. This is a
# trick to make month an unpadded integer.
month=`expr $month + 0`
# Subtract one from the current day.
day=`expr $day - 1`
# If the day is 0 then determine the last
# day of the previous month.
if [ $day -eq 0 ]; then
# Find the preivous month.
month=`expr $month - 1`
# If the month is 0 then it is Dec 31 of
# the previous year.
if [ $month -eq 0 ]; then
month=12
day=31
year=`expr $year - 1`
# If the month is not zero we need to find
# the last day of the month.
else
case $month in
1|3|5|7|8|10|12) day=31;;
4|6|9|11) day=30;;
2)
if [ `expr $year % 4` -eq 0 ]; then
if [ `expr $year % 400` -eq 0 ]; then
day=29
fi
else
day=28
fi
;;
esac
fi
fi
case $day
in 1|2|3|4|5|6|7|8|9) day='0'$day
esac
case $month
in 1|2|3|4|5|6|7|8|9) month='0'$month
esac
# echo $year$month$day
}
# cacl the date dividing value
caclDividingValue()
{
echo keeydays:$KEEP_DAYS
i=1
while [ $i -le $1 ]
do
#echo $i
getLastDay $year $month $day
i=$(($i+1))
done
}
#delete the old logs before the keep days
caclDividingValue $KEEP_DAYS
sdate="$year$month$day"
echo The log files will be deleted before $sdate.
for file in `ls $LOG_PATH`
do
# echo here$file
if [ "$file" -lt "$sdate" ]; then
echo $LOG_PATH/$file
snow=`date`
echo [$snow] delete $LOG_PATH/$file >> $LOG_DEL_LOGFILE
rm -fr $LOG_PATH/$file
fi
done
2、加上定时处理功能,输入crontab -e, 增加行:
<!-- [if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:PunctuationKerning/>
<w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing>
<w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery>
<w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:Compatibility>
<w:SpaceForUL/>
<w:BalanceSingleByteDoubleByteWidth/>
<w:DoNotLeaveBackslashAlone/>
<w:ULTrailSpace/>
<w:DoNotExpandShiftReturn/>
<w:AdjustLineHeightInTable/>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:UseFELayout/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
</w:WordDocument>
</xml><![endif]--><!-- [if gte mso 9]><xml>
<w:LatentStyles DefLockedState="false" LatentStyleCount="156">
</w:LatentStyles>
</xml><![endif]--><!-- [if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";
mso-ansi-language:#0400;
mso-fareast-language:#0400;
mso-bidi-language:#0400;}
</style>
<![endif]-->30 3 * * *
/home/scripts/logmonitor.sh > /home/scripts/lcron.log 2>&1
每天3:30执行
该脚本
分享到:
相关推荐
详细介绍,如何在aix系统下面清除 oracle 归档日志 步骤。
帮你快速了解aix环境下的shell开发基本知识
aixshell 编程
AIX操作系统错误日志及日常维护。 一、系统故障记录(errorlog) 二、控制面板上的LED 代码 三、其他用于收集系统信息的命令
aix常用操作命令(vi,shell),这个是公司内部培训的采用命令
ibm au23 for aix 5l korn and bash shell programing
AIX 系统errpt日志分析方法,对初学者来说又一定的帮助
在写IBM AIX K Shell script时,感觉不那么友好,主要是有一些格式细节要求比较严格,不太习惯,后来写惯了也就好了,下面的三个script是我为公司最近写的 一个自动备份shell script,基本要求就是每天晚上23:00自动跑起来...
介绍AIX文件系统日志详解,针对对象主要是UNIX学习者
AIX-SHELL基本编程.doc 根据网上资料下载的,整理了拿来看,顺便发个同行 学习如何使用 bash 脚本语言编程,将使 Linux 的日常交互更有趣和有生产力,同时还可以利用那些已熟悉和喜爱的标准 UNIX 概念(如管道和...
很强悍的SHELL开发参考文档,LINUX,UNIX,SHELL,AIX,VI,脚本 LINUX,UNIX,SHELL,AIX,VI,脚本
一个AIX shell字符颜色demo,放到aix环境赋权限执行即可~
Collection data hmac
sdfghjklp;lkjhgtfrdesasjoiuytrewqaswdertyu
AIX 5L Korn and bash Shell Programming
AIX 通用健康检测脚本,本人编制AIX5.X -AIX7.2通用。使用方法,把文件复制到/bin目录,用命令赋予权限:#chmod 755 AIX,然后就可以直接运行,#AIX,会自动检测设备健康状态,在屏幕显示出来并保存文件包便于查询,...
该函数实现当前日期的钱N天和当前日期的后N天计算; yyyyMMdd -N ##yyyyMMdd日期前N天 yyyyMMdd N ##yyyyMMdd日期后N天
AIX shell基础.docx