0

I am running an Ubuntu EC2 instance as an "ubuntu" user.When I create a cron job for checking the mysql status saving the logs in /var/log/filename.log,I receive a mail(via installed postfix) and the log states: "cannot create /var/log/filename.log:permission denied".When the cron job is created to save logs in /home/ubuntu/filename.log and the ownership has been changed for the /var/log/filename.log, no mails were received.

My path variable: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

What is the best way to see my cron job's message?

0

The problem is that your user, ubuntu, doesn't have permission to create new file in the folder /var/log.

ls -la /var/ | grep log
drwxr-xr-x 14 root root   4096 Aug 17 09:08 log

So what you can do is to create the file with root user or sudo command and then change the file ownership to 644.

sudo touch /var/log/filename.log
sudo chown ubuntu:ubuntu /var/log/filename.log
0

On an EC2 Ubuntu instance, the standard ownership for /var/log is root:syslog.

If you want your ubuntu user to be able to create files in /var/log, you need to add the user to the syslog group.

usermod -aG syslog ubuntu

You need to log out and log back in for the new group permissions to take effect.

Be very careful. Giving elevated permissions to your standard user is generally a bad idea. If you have permission to create files in /var/log you also have permission to delete them, which can hurt other things. Consider storing your logs in some location other than /var/log. If they must be there, consider creating a new user to run the background jobs and giving that user the needed permissions or, alternatively, placing the jobs in the standard system cron spaces, which already possess the needed permissions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.