我有一个从命令行运行良好的bash脚本,但是从incrontab调用它时,替换失败。脚本运行,但是$(...)中的命令失败:(
我的incrontab -e:
/home/kelly/summer IN_CREATE /bin/bash /usr/share/summerwear/notify.sh
在我的脚本(notify.sh)中:
#!/bin/bash
swimwear=$(grep -i "swimsuit" "/home/kelly/summer/inquiry.txt")
echo "The swimwear request is $swimwear" > /home/kelly/log.txt
我的日志文件的内容如下:
泳装要求是
..
传入的query.txt文件的示例:
请求1-泳衣-蓝色-白天-非正式
请求2-礼服-黑色-夜间-正式
..
从incron.conf设置PATH和SHELL似乎没有什么作用。
我也尝试过类似这样的事情:
#!/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
我能想到的每一个组合:
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"))
..以及单引号,双引号,无引号等的无穷组合。 ...以及指定grep PATH:
swimwear=$(/bin/grep -i "swimsuit" "/home/kelly/summer/inquiry.txt")
(等)... 有几篇有关设置和/或指定cron作业,crontab等的PATH和SHELL的文章,但是我没有看到很多关于“ incrontab”的具体信息。
非常感谢您的帮助!