I've been scanning forums for days/weeks now on this issue, but I have a raspberry pi that I'm trying to setup a cleaning script on. The script works well manually, but not via cron (cron shows the job running, but nothing in errors).
The cron entry (and execution) is:
Jul 8 07:02:01 E1 CRON[16785]: (root) CMD (/usr/bin/php /extHDD/subdir/subdir/subdir/cleanbackups.php >>/extHDD/subdir/subdir/subdir/cleanbackups.log 2>&1)
The "cleanbackups.log" only shows blank lines when the script runs.
The script is designed like this (set to expire older than 2 days and 1hr):
cat cleanbackups.php
#!/bin/bash
export PATH=/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/extHDD/subdir/subdir/subdir
<?php
$files = glob("backup-*_xyz.tar.gz");
foreach($files as $file) {
if(is_file($file)
&& time() - filemtime($file) >= 2*1*0*0) { // 7 days
unlink($file);
}
}
?>
The script runs with:
- php cleanbackups.php
- php -f cleanbackups.php
- php -q cleanbackups.php
- /usr/bin/php cleanbackups.php
- /usr/bin/php -f cleanbackups.php
- /usr/bin/php -q cleanbackups.php
This cron job is being modified on the root account, but using a standard user doesn't change the result.
Also, I already used chmod +X /path/to/cleanbackups.php, with no change.
Can anyone assist me in this? It's causing me severe anxiety :)