I am trying to use crontab running as a different user(due to required permissions) to create log files but my script doesnt seem to be executing
I am currently logged in as admin
and I want to run the script as www-data
so to edit the crontab I am using
sudo crontab -u www-data -e
Then entering
* * * * * /path/to/sh/mkLogFile.sh
mkLogFile.sh is a file that is owned by www-data
-rwxrw-r-- 1 www-data www-data 58 May 22 10:08 mkLogFile.sh
and its contents are
tday=`date +"%y%m%d%h%m"
`touch /path/to/log/$tday.log`
In the crontab I have also tried the following without making the file first
* * * * * /path/to/file/populateLogs >/path/to/log`date +%y%d%m`.log
none of these work to either create the file or to create and populate the file.
If I run any of these using
sudo -u www-data ./mkLogFile.sh
or any other command from the crontab they work, but not when run from the crontab. Other scripts have run in this way just none that make a file.
the log
dir is also owned by www-data
and has full permissions.
drwxrwxrwx 2 www-data www-data 4096 May 22 10:40 log
Is there something glaringly obvious that I'm doing wrong ? or is there a better way of doing this ?