科技知識動態:shellexecuteex失敗 linux下刪除7天前日志的代碼php+shell

導讀 跟大家講解下有關shellexecuteex失敗 linux下刪除7天前日志的代碼php+shell,相信小伙伴們對這個話題應該也很關注吧,現在就為小伙伴們說

跟大家講解下有關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中文網

免責聲明:本文由用戶上傳,如有侵權請聯系刪除!