You are not logged in.

#1 2014-08-24 04:59:23

Bailando
Member
From: Hungary
Registered: 2013-08-19
Posts: 133
Website

How can I watch if a given file is modified?

I would like to watch if a given file is modified and then run a script automatically if any modification occurs. I found the command http://linux.die.net/man/1/inotifywatch but it only collects the statistics and print it out if the interrupt signal is received (Ctrl + C or time elasped).

Offline

#2 2014-08-24 05:09:20

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,426
Website

Re: How can I watch if a given file is modified?

No, look at the EVENTS section of the man page: inotifywait can be run in a while loop and will trigger an action if, for example, attrib is set.


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#3 2014-08-24 10:01:50

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: How can I watch if a given file is modified?

What exactly do you want to do? Maybe e.g. an hourly rsync would be enough?

Offline

#4 2014-08-24 11:35:48

Dyspareunia
Member
Registered: 2014-08-10
Posts: 20

Re: How can I watch if a given file is modified?

I've used incron for this in the past, maybe that would suit your needs a bit better?

Careful tho... I've messed my system up pretty good a few times with this tool...

Offline

#5 2014-08-24 11:56:39

tomk
Forum Fellow
From: Ireland
Registered: 2004-07-21
Posts: 9,839

Re: How can I watch if a given file is modified?

I'd recommend incron too, and I haven't messed up my system with it ever. smile

Offline

#6 2014-08-24 12:34:45

emeres
Member
Registered: 2013-10-08
Posts: 1,570

Re: How can I watch if a given file is modified?

For something more complex with logging, you may want to look into systemd paths directives PathChanged and PathModified.

man systemd.path

Offline

Board footer

Powered by FluxBB