I tried to set up automated processing of imported pictures and videos from the digicam.
Custom Script
me@mymachine ~ $ ll /home/me/scripts/autorename-avmedia-exif.sh
-rwxr-xr-x 1 me me 603 Aug 7 22:50 /home/me/scripts/autorename-avmedia-exif.sh*
Contents:
#!/bin/bash
# Argument
if [ $# -eq 1 ] ; then
# Only one argument
file=$1
else
# No argument
echo "Usage: $0 target-file"
exit 1
fi
/bin/echo "$0 started" > /home/me/tmp/autorename.log
exiftool -overwrite_original_in_place -P '-filename<CreateDate' -d "%Y-%m-%d %H-%M-%S%%-c.%%le" "$file"
echo "exiftool returned: $?" >> /home/me/tmp/autorename.log
Incron Permissions:
me@mymachine ~ $ sudo cat /etc/incron.allow
me
root
Incron Watch:
me@mymachine ~ $ incrontab -l
/home/me/Bilder/Import IN_CLOSE_WRITE /bin/bash /home/me/scripts/autorename-avmedia-exif.sh "$@/$#" > /home/me/tmp/autorename-avmedia-exif.log
Syslog:
Aug 7 22:36:26 mymachine incrond[1391]: (me) CMD (/bin/bash /home/me/scripts/autorename-avmedia-exif.sh "/home/me/Bilder/Import/DSC01037.JPG" > /home/me/tmp/autorename-avmedia-exif.log)
Problem: Nothing happens. The script is not executed.
When copy past'ing the line from syslog into a terminal, the script works without a problem.
Replacing the script call with touch /home/me/tmp/test.incron
works and the test file is created.
So this has to be an environmental problem, but I already prefixed the script call with /bin/bash
and added full paths. What else is missing?
Thank you waltinator for your help, this pushed me into the right direction.
I don't know what the problem previously was, but as soon as I added the output redirection
> /home/me/tmp/autorename-avmedia-exif.log
, it couldn't work, cause incron seems to not know about it and hands this part over to the script as arguments. There my script failed, as it expects only one argument and there was no logging for the else case.Just to be clear: the script was called successfully, but it exited at the top, due to a wrong number of arguments.
I found this out with putting
touch /home/me/incron#.test
lines all over the script, while#
was an incrementing number.