2

I have a file /var/logs/apache2/error.log. And every time I boot, Its file permission is changed to default (unwritable) by the system. So, i have to run chmod command every time i boot-up. How to change it's file permission permanently.

6
  • 1
    Question - why? What is it you are trying to do that requires write access? Normal logging processes are generally recommended.
    – Rory Alsop
    Mar 30, 2011 at 12:10
  • @RoryAlsop to debug ajax, i need to check into error.log. And this is so full of logs. I normally delete it, and look for changes. But due to it's permission, is not editable.
    – S L
    Mar 30, 2011 at 12:15
  • @explorex - good range of tools allow you to manage logs without deleting. I always use a combination of grep and tail, which makes life very easy.
    – Rory Alsop
    Mar 30, 2011 at 12:22
  • @RoryAlsop is grep and tail programs or soft packages?
    – S L
    Mar 30, 2011 at 12:27
  • 1
    @explorex - both part of unix/linux. Tail lets you look at the last lines of a file (unixhelp.ed.ac.uk/CGI/man-cgi?tail) and grep lets you search through a file for instances you want to find (unixhelp.ed.ac.uk/CGI/man-cgi?grep). Well worth understanding the power of grep - invaluable!
    – Rory Alsop
    Mar 30, 2011 at 12:32

3 Answers 3

5

Log files are usually created by logrotate. The apache logfiles definition is stored on /etc/logrotate.d/apache2

The file looks like this in one of my servers:

/var/log/apache2/*.log {
        weekly
        missingok
        rotate 52
        compress
        delaycompress
        notifempty
        create 640 root adm
        sharedscripts
        postrotate
                if [ -f "`. /etc/apache2/envvars ; echo ${APACHE_PID_FILE:-/var/run/apache2.pid}`" ]; then
                        /etc/init.d/apache2 reload > /dev/null
                fi
        endscript
}

If you look at the create option, the values after the keyword are the permissions, user and group. Just edit your file and change this values.

4

I'm guessing anacron is running logrotate at boot time.

If so, try editing the configuration file /etc/logrotate.d/apache2, and change

create 640 root adm

to whatever you prefer, e.g.

create 666 root adm

But other than the apache2 service, what else needs to write to this file?

If this is on a server, it's probably a bad idea to make the file world writable. For example, if somebody breaks in to your system, they can remove the log entries that would help you find the problem.

If you want read access, it might be better to add yourself to the adm group, e.g.

gpasswd -a `whoami` adm

This would also help if you really do need write access, e.g.

create 660 root adm

would be sufficient.

3
  • The usual reason is letting some customers or some software (traffic analysis, monitoring) access to the logs without granting it extra privileges that could be a security risk. Mar 30, 2011 at 10:48
  • Read access, probably OK. But the poster said write access was required too.
    – Mikel
    Mar 30, 2011 at 10:51
  • Ouch, now I'm wondering too... Mar 30, 2011 at 12:03
3

As per the discussion in comments, for the purpose the OP is trying to achieve (looking at a simple subset of logs for a specific purpose), this may be an appropriate alternative solution:

Tail will let you look at the last lines of a file

Grep lets you search through a file for instances you want to find

Both are available as part of Unix/Linux and should be part of your essential toolkit.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .