problem with cron

vinceman

New member
Joined
Jan 23, 2008
Messages
4
Hi all,

I'am newbie with php, and i'am actually working to get a script to work as a cron job on DA, but a need help!

Actually it is impossible for me to know if this script work or if not working, (there is no log or something else in the script to see that)


Here what i put i the crontab:
*/5 * * * * /home/user/delfiles.php

Script is set with permissions 777

Script is actually at the root emplacement.(when i connect with ftp with this user i see the script at the root)

This script is used to delete automatically all the .jpg in the folder "Test1" when this files are aged more than 3600s (1hour)


Here the script used (php):

<?php
//notre fonction paramétrée
suppression( "Test1" , "jpg" , "3600" );

//la fonction en question
function suppression($dossier_traite , $extension_choisie, $age_requis)
{
//on ouvre le dossier
$repertoire = opendir($dossier_traite);

//on lance notre boucle qui lira les fichiers un par un
while(false !== ($fichier = readdir($repertoire)))
{
//on met le chemin du fichier dans une variable simple
$chemin = $dossier_traite."/".$fichier;

//les variables qui contiennent toutes les infos nécessaires
$infos = pathinfo($chemin);
$extension = $infos['extension'];

$age_fichier = time() - filemtime($chemin);

//on n'oublit pas LA condition sous peine d'avoir quelques surprises :p
if($fichier!="." AND $fichier!=".." AND !is_dir($fichier)
$extension == $extension_choisie AND $age_fichier > $age_requis)
{
unlink($chemin);
}
}
closedir($repertoire); //on ferme !
}
?>


The problem is these images *.jpg under the folder "Test1" are never deleted (aged more than 3600s) so i think the crontab configuration
in DA i set is not good, or this script not working at all !


- What do you mean? ,
- did i set correctly crontab?,
- and do you think my script php is correct?


Thanks for the all help you can give !!! (and sorry for my bad english here)


Vincent
 
Here's what your cron should look like:

*/5 * * * * /usr/local/bin/php /home/user/delfiles.php

You forgot to tell PHP to parse that php file ;)

To see if things are working, check /var/log/cron.
 
Here's what your cron should look like:

*/5 * * * * /usr/local/bin/php /home/user/delfiles.php

You forgot to tell PHP to parse that php file ;)

To see if things are working, check /var/log/cron.

ok but this method also should be used when we used a server hosting ? (it's the case for me)
 
Ok thank for your help GXX

I let you know if problem persist when i setup this in the evening

Vincent
 
Sorry , not working :(

Script was set to this :
*/5 * * * * /usr/local/bin/php /home/user/delfiles.php

Where can i find this folder /var/log/cron ? (the only folder "logs" you see in the root was created by me and is empty i confirm that)

See what i have under the root in attachment, hope that will help to
understand.
 

Attachments

Try this:
Code:
*/5 * * * * /usr/local/bin/php /home/[COLOR="Red"]<user>[/COLOR]/domains/[COLOR="Red"]<domainname>[/COLOR]/public_html/delfiles.php
Change the parts in red
 
Back
Top