incron on Ubuntu - bash script called by incrontab - dollar parentheses $(command) command substitutions fail

312 Views Asked by At

I have a bash script that runs fine from the command line, but when it's called from incrontab the substitutions fail. The script runs, but the commands in $(...) fail :(

My incrontab -e :

/home/kelly/summer IN_CREATE /bin/bash /usr/share/summerwear/notify.sh

in my script (notify.sh) :

#!/bin/bash
swimwear=$(grep -i "swimsuit" "/home/kelly/summer/inquiry.txt")
echo "The swimwear request is $swimwear" > /home/kelly/log.txt

The contents of my log file then look like this:

The swimwear request is

..

An example of the incoming inquiry.txt file:

request 1 - swimsuit - blue - daytime - informal

request 2 - gown - black - nighttime - formal

..

Setting the PATH and SHELL from incron.conf doesn't seem to make a difference.

I have also tried variations of stuff like this:

#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
SHELL=/bin/bash
swimwear=$(grep -i "swimsuit" "/home/kelly/summer/inquiry.txt")
echo "swimwear equals $swimwear" > /home/kelly/log.txt

And every combination I can think of:

swimwear=$(grep -i "swimsuit" "/home/kelly/summer/inquiry.txt")
swimwear=$("grep -i swimsuit /home/kelly/summer/inquiry.txt")
swimwear=$(grep -i 'swimsuit' "/home/kelly/summer/inquiry.txt")
swimwear=$(grep -i swimsuit "/home/kelly/summer/inquiry.txt")
swimwear=$(grep -i $("swimsuit" "/home/kelly/summer/inquiry.txt"))
swimwear=$( $(grep -i "swimsuit" "/home/kelly/summer/inquiry.txt"))

..and endless combinations of single-quotes, double quotes, no-quotes, etc. ...as well as specifying the grep PATH:

swimwear=$(/bin/grep -i "swimsuit" "/home/kelly/summer/inquiry.txt")

(etc.)... There are several posts dealing with setting and/or specifying the PATH and SHELL for cron jobs, crontab, etc., but I'm not seeing a whole lot of information out there regarding "incrontab" specifically.

Any help is greatly appreciated!

0

There are 0 best solutions below