Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 $@$#
like image 637
max Avatar asked Jan 26 '16 16:01

max


People also ask

How do you reset Incrontab?

-d (or --reload) option causes reloading the current table by incrond(8). It is done through "touching" the table (writing into it without modifying it).


1 Answers

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
like image 138
Alexander Baltasar Avatar answered Oct 14 '22 10:10

Alexander Baltasar