跟大家讲解下有关shellexecuteex失败 linux下删除7天前日志的代码php+shell,相信小伙伴们对这个话题应该也很关注吧,现在就为小伙伴们说说shellexecuteex失败 linux下删除7天前日志的代码php+shell,小编也收集到了有关shellexecuteex失败 linux下删除7天前日志的代码php+shell的相关资料,希望大家看到了会喜欢。
PHP版本:复制代码 代码如下:
/** * 删除7天前的日志 * @param $logPath */ function del7daysAgoLog($logPath) { if(empty($logPath))return; $handle = opendir($logPath); while(($file = readdir($handle)) !== false){ $pos = strpos($file, '.log'); if ($pos !== false && (strtotime("-1 week") > fileatime($logPath . $file))) { unlink($logPath . $file); } } }
shell 版本复制代码 代码如下:
#!/bin/sh function del7daysAgoLog (){ for file in $(ls $1) do if ["${file##*.}"="log"] then ctime=$(stat $1/$file -c"%y") ctimeU=$(date -d"$ctime"+%s) now=$(date +%s) SevenDaysAgo=$(($now - 36000 * $Days)) if [ $SevenDaysAgo -gt $ctimeU ] then $(rm $file)#此处删除文件 fi else echo""fi done } Days=7 Path="/var/www/***/log"del7daysAgoLog $Path $Days
shell 版本比较麻烦 关键我linux转换不熟悉以上就介绍了shellexecuteex失败 linux下删除7天前日志的代码php+shell,包括了shellexecuteex失败方面的内容,希望对PHP教程有兴趣的朋友有所帮助。
来源:php中文网