Just to add, the reason why i wanted to keep sub directories was because i want a record of how many files have been on the server in our history as a whole, and for that im counting the number of sub directories.
I missed the part about .exe …
. Well, in that case
find /path/to/your/upload/directory -name *.exe -type f -mmin +240 -exec rm {} \\;
-name *.exe = all .exe files
-type f = files only (leave directories alone)
-mmin = at least 240 minutes (=4 hours) old
-exec rm {} \; = delete the result
![]()
Now iterate it across all subdirectories of /upload and you’re golden, yeah.
It already does that …
It does exactly what your script does ![]()
This seemed to work a treat when i ran it manually, but when through Cron, i get the following errors thrown up.
`PHP Warning: Directive ‘safe_mode’ is deprecated in PHP 5.3 and greater in Unknown on line 0
PHP Warning: Invalid argument supplied for foreach() in /var/www/vhosts/uploadvillage.com/httpdocs/cleanup.php on line 9`
PHP Warning: Directive 'safe_mode' is deprecated in PHP 5.3 and greater in Unknown on line 0 PHP Warning: Invalid argument supplied for foreach() in /var/www/vhosts/uploadvillage.com/httpdocs/cleanup.php on line 7
My cronjob code is:
*/1 * * * * /usr/bin/php /var/www/vhosts/uploadvillage.com/httpdocs/cleanup.php
Sound to me like safe_mode is defined in php.ini for the cli where it shouldn’t be; that line should be commented out.
If you have access to that php.ini yourself you can do this yourself, if you don’t you should ask your hoster. Be sure to send them that error message when you do.
Scallio i think i might try your code.
Can i set up your code as a cron?
and checking php.ini
file_uploads = On
post_max_size = 50m
upload_max_filesize = 50m
register_globals = On
error_log = error_log
error_reporting = 2039
log_errors = On
I turned off safe mode a week or so ago.
Yes, although I would put it in a script just to make sure. Suppose you call it cleanup.sh :
cleanup.sh
#!/bin/sh find /path/to/your/upload/directory -name *.exe -type f -mmin +240 -exec rm {} \\;
Just make sure you set /path/to/your/upload/directory correctly – triple check this, you don’t want the script to start randomly deleting *.exe from your hard drive.
Also, make sure that script is executable
chmod +x ./cleanup.sh
Now you can run it
./cleanup.sh
Just to check with you, is ./ the home folder on the server? Like the highest directory?
EDIT: Ignore me, ive put it in etc/cleanup.sh and ill see how it goes!
Ok, im a pain in the ass
/bin/sh: /etc/cleanup.sh: /bin/sh^M: bad interpreter: No such file or directory
Think i need sysutils and dos2unix? >> http://ubuntuforums.org/showthread.php?t=327108
OK! Solution in sight i think. Im doing this from cron:
*/1 * * * * /usr/bin/find /var/www/vhosts/uploadvillage.com/httpdocs/Uploads -name *.exe -type f -mmin +240 -exec rm {} \;
And it is working by the looks of things.
Thanks Scallio, really appreciate your help.