papaface Posted July 19, 2009 Share Posted July 19, 2009 Hello, I have a script on my server which is supposed to go through certain directories and delete the files within them if they're more than 1 day old. However the script is not working (i.e nothing is being deleted) and I have no idea why. Does anyone know why this may be happening: <?php /* Cleanup Script */ //set_time_limit(900); error_reporting(1); ini_set('display_errors',1); function execInBackground($cmd) { if (substr(php_uname(), 0, 7) == "Windows"){ pclose(popen("start /B ". $cmd, "r")); } else { exec($cmd . " > /dev/null &"); } } function is_empty_dir($dir) { if ($dh = @opendir($dir)) { while ($file = readdir($dh)) { if ($file != '.' && $file != '..') { closedir($dh); return false; } } closedir($dh); return true; } else return false; // whatever the reason is : no such dir, not a dir, not readable } //Do processed execInBackground('find /home/***/conv/processed -mtime +1 -exec rm {} \;'); execInBackground('find /home/***/conv/uploaded -mtime +1 -exec rm {} \;'); execInBackground('find /home/***/conv/tmp -mtime +1 -exec rm {} \;'); //Do Cache&Stored execInBackground('find /home/***/public_html/tmpvidstore -mtime +1 -exec rm {} \;'); //Do Logs execInBackground('find /***/fetchmp3/public_html/convlog -mtime +1 -exec rm {} \;'); //Do Cachefind /home/***/public_html/vidcache/o -mtime +7 -exec rm {} \; $cachedirs = array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','q','y','z'); foreach($cachedirs as $value) { if(!is_empty_dir('/home/***/public_html/vidcache/'.$value)) execInBackground('find /home/***/public_html/vidcache/'.$value.' -mtime +7 -exec rm {} \;'); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/166507-solved-cleanup-script-doesnt-execute/ Share on other sites More sharing options...
Daniel0 Posted July 19, 2009 Share Posted July 19, 2009 Any reason why you don't just write it in bash? Quote Link to comment https://forums.phpfreaks.com/topic/166507-solved-cleanup-script-doesnt-execute/#findComment-878038 Share on other sites More sharing options...
papaface Posted July 19, 2009 Author Share Posted July 19, 2009 Any reason why you don't just write it in bash? I didn't write the script, my friend did. What do you propose and I'll give it a try Quote Link to comment https://forums.phpfreaks.com/topic/166507-solved-cleanup-script-doesnt-execute/#findComment-878042 Share on other sites More sharing options...
papaface Posted July 19, 2009 Author Share Posted July 19, 2009 I've found the issue. It is the permissions on the files. They need to be set to 755 Thanks for your help anyways Daniel Quote Link to comment https://forums.phpfreaks.com/topic/166507-solved-cleanup-script-doesnt-execute/#findComment-878047 Share on other sites More sharing options...
Daniel0 Posted July 19, 2009 Share Posted July 19, 2009 Looks like something like this: #!/bin/bash find /home/***/conv/processed -mtime +1 -exec rm {} \; find /home/***/conv/uploaded -mtime +1 -exec rm {} \; find /home/***/conv/tmp -mtime +1 -exec rm {} \; find /home/***/public_html/tmpvidstore -mtime +1 -exec rm {} \; find /***/fetchmp3/public_html/convlog -mtime +1 -exec rm {} \; for DIR in `echo /home/***/public_html/vidcache/*` do find $DIR -mtime +7 -exec rm -rf {} \; done Would do the same. Quote Link to comment https://forums.phpfreaks.com/topic/166507-solved-cleanup-script-doesnt-execute/#findComment-878049 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.