myGully.com

myGully.com (https://mygully.com/index.php)
-   Entwicklung & Programmierung (https://mygully.com/forumdisplay.php?f=72)
-   -   cronjob problem (https://mygully.com/showthread.php?t=4807258)

carlo1 20.05.17 12:40

cronjob problem
 
Hallo
ich hab einen webspace mit 50GB und meine 2 Webcams übertragen die aufnahmen dorthin.
da ja ziemliche datenmengen zusammenkommen, möchte ich einen Cronjob verwenden, der mir die Files, die älter als 15 tage sind, automatisch löscht. der cronjob soll halt 1x am tag dies erledigen. mein Webspaceanbieter kann dies auch.

In meinem Coding ist aber irgend ein Fehler drin, sodass die Files nicht gelöscht werden. Vielleicht kann mir jemand helfen.

Ausgangslage: Das Speicherverzeichnis lautet: /FI9805W_00626Exxxxx/snap2 und die files darin MDAlarm_20170515-070726.jpg
MDAlarm_20170515-070727.jpg
MDAlarm_20170515-070728.jpg

Mein Cronjob S***** ist folgendes:
<?php

function delete_files($dir)
{
$handle = opendir($dir);
$cnt = 0;

$timeout = time()-60*60*24*2;

while(false !== ($file = readdir( $handle ))) {
$absfile = $dir . $file;
if(is_dir($absfile)) continue;

$mtime = filemtime($absfile); // ggf. filectime() statt filemtime() verwenden

printf("%s: mtime = %s, timeout = %s\n", $absfile, strftime("%Y-%m-%d,%H:%M:%S",$mtime), strftime("%Y-%m-%d,%H:%M:%S",$timeout));
if($timeout > $mtime) {
unlink( $absfile );
printf("%s geloescht\n", $absfile);
$cnt++;
}
}
closedir($handle);
echo 'Anzahl: ' . $cnt;
}

delete_files('xxxx/foscam/FI9805W_00626Exxxxx/record/');
delete_files('xxxx/foscam/FI9805W_00626Exxxxx/snap2/');
?>

Dieses S***** hat mir jemand geschrieben, funktionierte schon 1x. Es dürfte sich jedoch etwas verändert haben am system und jetzt klappt es nicht mehr. Ich selbst hab null ahnung von S*****en.
Weiß hier nichtmal, wo ich das Alter der Datei einstellen kann?!

Eine 2. Variante hab ich auch noch, funktioniert aber auch nicht.
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$dir = 'xxxx/site21x/web/foscam/FI9805W_00626xxxx/snap2/';
$handle = opendir($dir);
$cnt = 0;

$timeout = time()-60*60*24*7;

while(false !== ($file = readdir( $handle ))) {
$absfile = $dir . $file;
if(is_dir($absfile)) continue;

$mtime = filemtime($absfile); // ggf. filectime() statt filemtime() verwenden

printf("%s: mtime = %s, timeout = %s\n", $absfile, strftime("%Y-%m-%d,%H:%M:%S",$mtime), strftime("%Y-%m-%d,%H:%M:%S",$timeout));
if($timeout > $mtime) {
unlink( $absfile );
printf("%s geloescht\n", $absfile);
$cnt++;
}
}
closedir($handle);
echo 'Anzahl: ' . $cnt;
error_reporting(E_ALL);
ini_set('display_errors', 1);
$dir = '/xxxxx/site21xx/web/foscam/FI9805W_00626xxxx/record/';
$handle = opendir($dir);
$cnt = 0;

$timeout = time()-60*60*24*7;

while(false !== ($file = readdir( $handle ))) {
$absfile = $dir . $file;
if(is_dir($absfile)) continue;

$mtime = filemtime($absfile); // ggf. filectime() statt filemtime() verwenden

printf("%s: mtime = %s, timeout = %s\n", $absfile, strftime("%Y-%m-%d,%H:%M:%S",$mtime), strftime("%Y-%m-%d,%H:%M:%S",$timeout));
if($timeout > $mtime) {
unlink( $absfile );
printf("%s geloescht\n", $absfile);
$cnt++;
}
}
closedir($handle);
echo 'Anzahl: ' . $cnt;
?>


Alle Zeitangaben in WEZ +1. Es ist jetzt 14:20 Uhr.

Powered by vBulletin® (Deutsch)
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.