0

我有一个 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

我的日志文件的内容如下所示:

泳装要求是

..

传入的inquiry.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”的大量信息。

任何帮助是极大的赞赏!

4

0 回答 0