Tip: inotify cron


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Tip: inotify cron
# 1  
Old 01-31-2020
Tip: inotify cron

Dear members, moderators and others.

While working on <insert project>, a need has surfaced to watch a directory, and when a file comes, to do appropriate action.
So, i started writing some shell code, aware of linux inotify-tools package with inotifywait.

Also, i'm seeing a lot of similar request on these forums for such kind of actions.

Since linux kernel inotify subsystem is used extensively in the wild (for instance ClamAV), was sure that there was a cleaner way, not resorting to high level language programming

While surfing, i found a neat way to minimize the code used, tool called incrond
Same syntax as cron, minimal script to do action on received input.
The tool is available in EPEL repositories for CentOS, and standard ubuntu / debian ones.

So instead of monster shell code i ended up with a simple incrontab entry and a simple small shell script.

Keep it simple, stupid :
Code:
/directory/to/watch	IN_CLOSE_WRITE,IN_MOVED_TO   /path/to/script/script.sh $@ $#

So any file which gets closed (not necessarily written to) or moved to directory being watched will be processed by script.

From documentation :
Quote:
The following wildcards may be used inside command specification:
Code:
$$ dollar sign
$@ watched filesystem path (see above)
$# event-related file name
$% event flags (textually)
$& event flags (numerically)

Hopefully this will help you in your projects with same requirements and save time.

Regards
Peasant.
These 7 Users Gave Thanks to Peasant For This Post:
# 2  
Old 01-31-2020
I checked Fedora's repository. The package is called "incron"
Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Red Hat

Issues installing inotify-tools on RedHat Linux

I wish to install inotify-tools-3.20.1-2.4.x86_64.rpm on Linux and fire inotifywait command. Initially i was looking for "inotify-tools-3.xx.tar.gz" as instructed here http://jensd.be/248/linux/use-inotify-tools-on-centos-7-or-rhel-7-to-watch-files-and-directories-for-events I have... (9 Replies)
Discussion started by: mohtashims
9 Replies

2. Shell Programming and Scripting

Hotfolder with inotify-tools, loop FOR not working

I can not understand why this little script with a loop processes only one file. At boot in /etc/rc.local i wrote: /usr/local/bin/./myscript & This is myscript: #!/bin/bash while inotifywait -e create /HOTFOLDER/ ; do for fullname in /HOTFOLDER/*.xlsx; do if !... (22 Replies)
Discussion started by: pasaico
22 Replies

3. UNIX for Advanced & Expert Users

Dynamically add paths to inotify

I have initiated an inotify process with --fromfile option and the file contain the paths to be monitored. /usr/local/maldetect/inotify/inotifywait -d -r -o /usr/local/maldetect/inotify/inotify_log --fromfile /usr/local/maldetect/sess/inotify.paths.28364 --exclude (^/var/tmp/mysql.sock)... (2 Replies)
Discussion started by: anil510
2 Replies

4. UNIX for Advanced & Expert Users

[Tip] How to add individual delays to a cron job?

ofIn a big Unix environment you likely install cron jobs like this on a thousand systems: 39 15 * * * { /usr/local/monitoring/sendstats ; } >/dev/null 2>&1If all the system clocks are synchronized (usually via NTP), these jobs run *exactly* at the same time. If the cron job accesses a shared... (2 Replies)
Discussion started by: MadeInGermany
2 Replies

5. UNIX for Advanced & Expert Users

[Tip] How to add an application cron job?

A well established form of application cron jobs look like this: 39 15 * * * && /usr/local/monitoring/oracle/check_dbs.sh >/dev/null 2>&1The repetition makes it a long line, hard to read, hard to maintain. I suggest the following instead: 39 15 * * * { /usr/local/monitoring/oracle/check_dbs.sh... (1 Reply)
Discussion started by: MadeInGermany
1 Replies

6. Shell Programming and Scripting

Regexp tip

Hello, I'm just starting working on it. I'd like to get a tip For istance if I have a file like: a b c d e f .... and I wanna get: 1a & 2b & 3c 0d & 8e & 4f ..... I would like to use sed and come up with a regular expression that works.... (3 Replies)
Discussion started by: Dedalus
3 Replies

7. SCO

inotify() in SCO UNIX

Hi I'm going to write a program in C language to watch activity on file system in SCO UNIX openserver 5.0.6. Apparently Linux provide an API called "inotify" , I'm wondering what's the SCO UNIX package for this ? (1 Reply)
Discussion started by: javad1_maroofi
1 Replies

8. Solaris

Solaris; tip

plz explain TIP in solaris in detail. (11 Replies)
Discussion started by: karman0931
11 Replies

9. Solaris

tip into 280R

I need to use tip from machine A serial port to machine B serial port. Can someone point me to an example of the correct cable to use? Thanks. (1 Reply)
Discussion started by: dangral
1 Replies
Login or Register to Ask a Question