shellexecuteex failed. Code to delete logs 7 days ago under linux php+shell

WBOY
Release: 2016-07-29 08:44:05
Original
1305 people have browsed it

PHP version:

Copy codeThe code is as follows:


/**
* Delete logs from 7 days ago
* @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 version

Copy codecode As follows:


#!/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)#Delete file here
fi
else
echo ""
fi
done
}
Days=7
Path ="/var/www/***/log"
del7daysAgoLog $Path $Days


shell The version is more troublesome. The key is that I am not familiar with linux conversion.

The above introduces the php+shell code for deleting logs 7 days ago under Linux when shellexecuteex fails, including the content of shellexecuteex failure. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!