简体   繁体   中英

trouble getting incron inotify to work

so after alex answer here are my steps :

creating shell code

root@ip[/]# touch mylog.sh
root@ip[/]# nano mylog.sh

copying the code in the mylog.sh

#!/bin/bash
echo "File $1 created." >> /mylog.log

permission

root@ip[/]# chmod +x mylog.sh

creating the log file

root@ip[/]# touch mylog.log 

opening icron table

incrontab -e

putting new command in

/test/ IN_CREATE mylog.sh $@$#

reloading incron - creating a new file - checking the log file

root@ip[/]# incrontab --reload
requesting table reload for user 'root'...
request done

root@ip[/]# cd test
root@ip[/test]# touch newfile.txt

root@ip[/test]# cd /
root@ip[/]# nano mylog.log

but still empty log file ... am i missing something ?


finally calling shell script with full path did the trick so :

/test/ IN_CREATE /mylog.sh $@$#

You can usually find the incron logs in /var/log/messages

If you want to log events to a specific file you can use:

/test/ IN_CREATE mylog.sh $@$#

where mylog.sh is a shell script which handles the logging.

#!/bin/bash
echo "File $1 created." >> /home/myuser/filescreated.log

Don't forget to give execution permission to this shell script by chmod +x mylog.sh

Explanation: As soon as you start using parameters for your command which you're calling, you have to put it all into a shell script. Since incron don't pass the arguments to your command but interprets it as an argument for itself.

Don't forget to call incrontab --reload after changing the incrontab.

Another example

incrontab -e

/text/ IN_CREATE /home/myuser/mylog.sh $@ $#

mylog.sh

#!/bin/bash
echo "$(date) File $2 in $1 created." >> /home/myuser/log.txt

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM