You are not logged in.
Here's a simple change monitor I wrote in C. It takes as arguments a list of files and associated commands; when the file changes, its command is executed.
Example:
$ fcm -f some-file.txt -e 'echo some-file.txt changed!' \
> -E ad -f some-file-2.txt -e 'echo some-file-2.txt changed!'
'-E ad' preceding the second file causes FCM to examine both attribute change and data change.
AUR: http://aur.archlinux.org/packages.php?ID=35877
Mercurial repo: http://peasantoid.org:1024/fcm
Last edited by Peasantoid (2010-03-24 23:50:06)
Offline
Any reason it doesn't use inotify?
Offline
Because I felt like reinventing a few dozen wheels.
But seriously, *slaps self*. Didn't know about inotify, but this works for my purposes, so whatever.
*reads inotify(7)*
Last edited by Peasantoid (2010-03-23 23:31:27)
Offline
Haha fair enough. The concept is pretty good, sort of like "watch" for files. A front-end for FAM would be another way to do it, if you wanted to watch across NFS or some other corner cases.
Offline
Rewrote this to use the inotify API (thanks for the heads-up, tavianator). -c option is gone for the moment but will be back later in a different form.
As for FAM, that feels like overkill.
Last edited by Peasantoid (2010-03-24 21:13:43)
Offline
Finally fixed an annoying bug in which modifying a file with f.e. vim caused it to be dropped from the watch list. This was because of the way inotify handles a file being moved over another file. Not an inotify bug; more like a vim one, since it doesn't just do the smart thing and directly overwrite the file properly (by opening in truncate mode).
Offline
Actually vim is doing the smart thing. Basically this ensures that the save is an atomic operation; two apps could write to it at the same time otherwise.
Offline
Actually vim is doing the smart thing. Basically this ensures that the save is an atomic operation; two apps could write to it at the same time otherwise.
Yeah, I suppose that makes sense. But since it makes my job harder, I call it stupid.
Offline
Hi Peasantoid,
I try to use fcm to print mail by saving a mail to a specific file while having this running:
fcm -f ~/operamail.mbs -e "iconv -t iso8859-1 ~/operamail.mbs | a2ps -=mail -Pprinter"
However, fcm starts two processes, thus I get two printouts:
a2ps: unknown encoding `utf-8', ignored
[stdin (Mail Folder): 2 pages on 1 sheet]
a2ps: unknown encoding `utf-8', ignored
[stdin (Mail Folder): 2 pages on 1 sheet]
request id is printer-132344 (1 file(s))
[Total: 2 pages on 1 sheet] sent to the printer `printer'
request id is printer-132345 (1 file(s))
[Total: 2 pages on 1 sheet] sent to the printer `printer'
Both hardcopies show all text, so my first assumption that the file changes twice during writing is obviously not true. Can I overcome this in some way?
Offline
Maybe not FAM, but Gamin which superseeds FAM
Offline
Hi Peasantoid,
I try to use fcm to print mail by saving a mail to a specific file while having this running:
fcm -f ~/operamail.mbs -e "iconv -t iso8859-1 ~/operamail.mbs | a2ps -=mail -Pprinter"
However, fcm starts two processes, thus I get two printouts:
a2ps: unknown encoding `utf-8', ignored [stdin (Mail Folder): 2 pages on 1 sheet] a2ps: unknown encoding `utf-8', ignored [stdin (Mail Folder): 2 pages on 1 sheet] request id is printer-132344 (1 file(s)) [Total: 2 pages on 1 sheet] sent to the printer `printer' request id is printer-132345 (1 file(s)) [Total: 2 pages on 1 sheet] sent to the printer `printer'
Both hardcopies show all text, so my first assumption that the file changes twice during writing is obviously not true. Can I overcome this in some way?
Hrm. It may have something to do with me using inotify's IN_MODIFY instead of IN_CLOSE_WRITE. Run this in the source tree:
sed -i s/IN_MODIFY/IN_CLOSE_WRITE/ fcm.c
Then recompile and post back on whether it works.
# edit - clarity
Last edited by Peasantoid (2010-04-23 07:39:19)
Offline
That fixes it. Thanks for the quick reply.
Offline
A little patch that allows to install to nonstandard locations by "make PREFIX=/usr/local install":
# HG changeset patch
# User Thomas Dahms <thdahms@gmx.de>
# Date 1272025507 -7200
# Node ID 568bffa076982c3f687f8fc4bfabb9588acc48c1
# Parent 564ddf614ec48c0eeba70e119432e1d5ae7d0fec
add PREFIX to Makefile.
diff -r 564ddf614ec4 -r 568bffa07698 Makefile
--- a/Makefile Fri Apr 02 19:44:48 2010 -0400
+++ b/Makefile Fri Apr 23 14:25:07 2010 +0200
@@ -6,8 +6,9 @@
MAN = fcm.1
-BINDIR = $(DESTDIR)/usr/bin
-MANDIR = $(DESTDIR)/usr/share/man/man1
+PREFIX=/usr
+BINDIR = $(DESTDIR)/$(PREFIX)/bin
+MANDIR = $(DESTDIR)/$(PREFIX)/share/man/man1
.PHONY: all
all: $(BIN)
Offline
That fixes it. Thanks for the quick reply.
Okay, I'll commit that to the codebase then.
A little patch that allows to install to nonstandard locations by "make PREFIX=/usr/local install":
# HG changeset patch # User Thomas Dahms <thdahms@gmx.de> # Date 1272025507 -7200 # Node ID 568bffa076982c3f687f8fc4bfabb9588acc48c1 # Parent 564ddf614ec48c0eeba70e119432e1d5ae7d0fec add PREFIX to Makefile. diff -r 564ddf614ec4 -r 568bffa07698 Makefile --- a/Makefile Fri Apr 02 19:44:48 2010 -0400 +++ b/Makefile Fri Apr 23 14:25:07 2010 +0200 @@ -6,8 +6,9 @@ MAN = fcm.1 -BINDIR = $(DESTDIR)/usr/bin -MANDIR = $(DESTDIR)/usr/share/man/man1 +PREFIX=/usr +BINDIR = $(DESTDIR)/$(PREFIX)/bin +MANDIR = $(DESTDIR)/$(PREFIX)/share/man/man1 .PHONY: all all: $(BIN)
Thanks. For aesthetic reasons, I slightly modified the change so as to not include extraneous slashes in the paths. So instead of 'make PREFIX=/something install', you'd do 'make PREFIX=something install'. Note the missing slash.
(Changes have been committed and pushed.)
Offline