4

When I was trying to monitor the /var/log/secure or /var/log/message using watch command the output showed as /var/log/messages: Permission denied. Is it possible to monitor the /var/log/messages and /var/log/secure using watch command?

William
  • 13
  • 2
    You cannot watch a file, you have to give it a command to run, like Ulrich Schwarz's answer with tail. For a file, you can just use tail -f instead of watch. – meuh Apr 26 '16 at 13:38
  • As an extra tip, some files like /var/log/secure may rotate while tailing them, causing tail -f to stop printing logs. To continue following even if the file is rotated, use tail -F. – Mike Feb 08 '18 at 10:10

2 Answers2

5

Yes it is, but note that regular users don't have permission to read /var/log/messages and /var/log/secure.

sudo watch tail /var/log/messages 

worked fine here when I tried.

  • Hi Ulrich Schwarz, im using centos 6.7 , i used root account rather than normal user account, i got the error message when i was using root account only. – vinothsaran Apr 26 '16 at 13:19
  • Note that most sensible distros will make log files owned root adm and mode 0640 so anyone in the adm group can read them. If so, adduser regularjoe adm will allow regularjoe to read them once he logs in again. – Shadur-don't-feed-the-AI Jul 23 '16 at 18:01
1

You only have to issue:

sudo tail -f /var/log/messages

This will continuously add the latest line to the screen or file.

Stephen Kitt
  • 434,908