ns15
ns15

Reputation: 8814

run crontab as www-data to create a file with www-data as owner

I want to run a crontab command every 5 mins that executes a py script. The py script inturn generates a log file with midnight rotation within /var/www/logs/.The logs dir has 777 permission.

The log file has midnight rotation and when new file is created,it creates as root owner.How to ensure the ownership stays as www-data as some other scripts also write to the same file and having root ownership causes permission issue for other scripts.

One way is to put the command in,

crontab -u www-data -e

This works fine, but i want to maintain all my cron commands under root user.

I tried doing the same with sudo, but it creates with root as owner which not what i want.

Upvotes: 2

Views: 2608

Answers (2)

ns15
ns15

Reputation: 8814

Finally found a good solution for this problem.

Now I am using FACL in linux to set default permissions to all the files created in the logs directory.This way i can run all my crons in root. here is more on facl in linux

Also as mentioned in question, running crons under www-data caused few other logging related problems.

I used below command to set facl.

setfacl -m default:u:www-data:rw logs

Upvotes: 0

O M
O M

Reputation: 9

try adding ` && chown -R www-data

Upvotes: 1

Related Questions