Hello,
Trying to have fcron do the same than cronie, that is regenerate binary crontabs when /etc/crontab /etc/cron.d/ (or /etc/fcrontab since it is the same, but for fcron) change, I made a script to watch for /etc/cron.d/ and /etc/crontab and /etc/fcrontab if they exist (and then launch a script coming from debian that does all the regeneration work). However the issue I have is that I don't know how to have inotifywait do something when /etc/crontab or /etc/fcrontab is created since if I give a non-existing file as argument it will error out.
Also maybe I should not listen to all the events but only some.
And lastly maybe inotifywait is not the right tool?
The script is here: http://cvs.fedoraproject.org/viewvc/rpms/fcron/devel/fcron_watch_config?revi...
It is launched by an init script through another script, http://cvs.fedoraproject.org/viewvc/rpms/fcron/devel/daemon_fcron_watch_conf... that doesn't do anything else that starting it with setsid.
Anybody knows what I should do?
-- Pat
On Tue, Dec 2, 2008 at 3:30 PM, Patrice Dumas pertusus@free.fr wrote:
Hello,
Trying to have fcron do the same than cronie, that is regenerate binary crontabs when /etc/crontab /etc/cron.d/ (or /etc/fcrontab since it is the same, but for fcron) change, I made a script to watch for /etc/cron.d/ and /etc/crontab and /etc/fcrontab if they exist (and then launch a script coming from debian that does all the regeneration work). However the issue I have is that I don't know how to have inotifywait do something when /etc/crontab or /etc/fcrontab is created since if I give a non-existing file as argument it will error out.
I think if you want to catch file creation, you have to watch /etc, wait for create events and filter for the crontab files. So, I think it would have to be something like:
out=`inotifywait -e create /etc`; do if [ $? = 0 ]; then set -- $out case "$3" in crontab|fcrontab) do stuff ;; *) ;; esac fi
Or, more likely is that you'll have to check whether crontab or fcrontab exist initially and modify your command accordingly.
-- Dan
"Dan Nicholson" dbn.lists@gmail.com writes:
However the issue I have is that I don't know how to have inotifywait do something when /etc/crontab or /etc/fcrontab is created since if I give a non-existing file as argument it will error out.
I think if you want to catch file creation, you have to watch /etc, wait for create events and filter for the crontab files. So, I think it would have to be something like:
out=`inotifywait -e create /etc`; do if [ $? = 0 ]; then ...
Beside the syntax error, there is a race when file was created shortly before inotifywait. You have to check whether the file exists *after* inotify_add_watch(2) like in
https://www.cvg.de/people/ensc/wait-for-file.c
I filed a request a year ago to include similar functionality into inotifytools but this does not seem to implemented yet
http://sourceforge.net/mailarchive/message.php?msg_name=lylkdk440g.fsf%40ens...
Enrico
On Wed, Dec 03, 2008 at 09:26:25AM +0100, Enrico Scholz wrote:
Beside the syntax error, there is a race when file was created shortly before inotifywait. You have to check whether the file exists *after* inotify_add_watch(2) like in
https://www.cvg.de/people/ensc/wait-for-file.c
I don't really understand when the race condition could be, but in my case there is a sleep 30 anyway before launching a command that checks itself if the file exists, so I think this doesn't apply in my case.
I filed a request a year ago to include similar functionality into inotifytools but this does not seem to implemented yet
http://sourceforge.net/mailarchive/message.php?msg_name=lylkdk440g.fsf%40ens...
In both cases /etc is watched. That is something I would have liked to avoid, because it will cause my script to wake up a lot, compared with only looking at /etc/cron.d, /etc/crontab and /etc/fcrontab.
It looks like signalling that a file came into existence without watching the directory the file is in is not possible with inotify currently.
-- Pat
Patrice Dumas pertusus@free.fr writes:
Beside the syntax error, there is a race when file was created shortly before inotifywait. You have to check whether the file exists *after* inotify_add_watch(2) like in
https://www.cvg.de/people/ensc/wait-for-file.c
I don't really understand when the race condition could be,
e.g.
--- d=/tmp/test test -e $d/file || { sleep 100 inotifywait -e create $d } ---
and execute 'touch /tmp/test/file' during the 'sleep 10'.
--> script will hang forever.
In practice, the 'sleep' is shorter but present.
In both cases /etc is watched. That is something I would have liked to avoid, because it will cause my script to wake up a lot,
1. Why make it a script? A small C program makes 3 syscalls per new file
| $ strace ./a.out /tmp/foo1.c 100000 | ... | select(4, [3], NULL, NULL, {99987, 966000}) = 1 (in [3], left {99981, 19000}) | read(3, "\1\0\0\0\0\1\0\0\0\0\0\0\20\0\0\0xxcccvf5\0\0\0\0\0\0\0\0", 1024) = 32 | lstat("/tmp/foo1.c", 0x7fffc8d46ed0) = -1 ENOENT (No such file or directory)
2. /etc is not a directory where much file create operations happen
It looks like signalling that a file came into existence without watching the directory the file is in is not possible with inotify currently.
No; inotify(7) does not support this operation.
Enrico
On Wed, Dec 03, 2008 at 08:24:04PM +0100, Enrico Scholz wrote:
- Why make it a script? A small C program makes 3 syscalls per new file
Just because it is simpler to do, to debug... But maybe I'll do some C to include it directly in fcron.
- /etc is not a directory where much file create operations happen
Indeed. I didn't realized that only the file creations were acted upon.
So I'll certainly use your code or use it as a base for something directly in fcron.
-- Pat
Patrice Dumas wrote:
In both cases /etc is watched. That is something I would have liked to avoid, because it will cause my script to wake up a lot, compared with only looking at /etc/cron.d, /etc/crontab and /etc/fcrontab.
It looks like signalling that a file came into existence without watching the directory the file is in is not possible with inotify currently.
May be initialy check this file is exists, and if not just create (touch) empty if not? If we create new empty files, it is not add any job, but allow watch modify of it.
-- Pat
On Thu, Dec 04, 2008 at 11:50:39PM +0300, Pavel Alexeev (aka Pahan-Hubbitus) wrote:
May be initialy check this file is exists, and if not just create (touch) empty if not? If we create new empty files, it is not add any job, but allow watch modify of it.
I'd prefer not to create even empty files that are part of other packages. I will solve that by doing a specific C program to watch both files modifications and creation.
-- Pat