You are not logged in.

#1 2009-03-06 22:03:18

timm
Member
From: Wisconsin
Registered: 2004-02-25
Posts: 417

Monitoring file permission changes [ solved, kind of]

I have a configuration file on my server for a program that runs on Windows desktops.  For some reason, the permissions on that file keep getting changed, and it isn't being done manually by anyone.  I'm not sure why this is happening, and it seems to happen at random intervals.

Is there a way to monitor when the permissions on this file get changed?

Last edited by timm (2009-04-03 19:47:00)

Offline

#2 2009-03-06 22:23:10

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Monitoring file permission changes [ solved, kind of]

while sleep 1; do echo $(date) $(ls -l FILENAME); done > logfile.txt

Like this? Maybe make it sleep longer. If you want more specific data I think it's only worth it to run sed/awk on it only when you want to see the data, because putting it in here will either run those programs a lot or all the time, which isn't very nice.

Offline

#3 2009-03-07 04:50:49

codemac
Member
From: Cliche Tech Place
Registered: 2005-05-13
Posts: 794
Website

Re: Monitoring file permission changes [ solved, kind of]

Install inotify-tools from the AUR (Any TU's reading this thread who want another package? Someone should bring that to [community]).

Then run something like:

inotifywait -m -e attrib /that/file/that/is/changing ; echo "omg it changed"

Unless you want to use the C API and write your own app.. but I feel like that's not what you want.

Offline

#4 2009-03-10 19:43:49

timm
Member
From: Wisconsin
Registered: 2004-02-25
Posts: 417

Re: Monitoring file permission changes [ solved, kind of]

A couple questions:  Is there any way to get the inotify output to be used to change the permissions back?  It would seem I might be able to run a script using inotify at startup so that when the permissions get changed, they get changed back either immediately or on some set schedule.  Is a cron job the right tool for this?

And you're right; I have no idea what an API even is.

Offline

#5 2009-03-10 20:10:41

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Monitoring file permission changes [ solved, kind of]

I don't think it should be in crontab, if I understand codemac's example right, it will sleep until the attributes change, and then echo.

So if you want a constant monitor, wrap it around a while, and change the permissions right after the inotify command.

So

while true; do
inotifywait -m -e attrib /that/file/that/is/changing
chmod 644 /that/file/that/is/changing
done

Offline

#6 2009-03-11 01:31:14

Berticus
Member
Registered: 2008-06-11
Posts: 731

Re: Monitoring file permission changes [ solved, kind of]

http://fileschanged.sourceforge.net/

fileschanged is a GNU/Linux command-line utility that reports when files have been altered.

You'll need either fam or gamin installed to use this. I was gonna write a similar program myself. It'll most likely be better than having an infinitely look in a script or having crontab calling a script every second.

Offline

#7 2009-03-11 09:50:44

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Monitoring file permission changes [ solved, kind of]

And script might as well be just `chmod 644 /path/file` who cares if it already is 644.

Offline

#8 2009-04-03 19:46:28

timm
Member
From: Wisconsin
Registered: 2004-02-25
Posts: 417

Re: Monitoring file permission changes [ solved, kind of]

I tried automating the process using a couple of the ideas above, but while it seemed to work, the windows program that is served with this data started spewing all kinds of errors about various problems with the file.  I'm going back to fixing this manually for now.  It should work automatically, but for some reason it doesn't, and I'm wondering if it is because the file gets changed from r to rw at some point when the windows program is expecting something else.

Offline

Board footer

Powered by FluxBB