路径未从 crontab 设置

Path not get set from crontab

非常简单,但无法正常工作。路径未设置。

定时任务表:

* * * * * source /home/inst1/.profile; /home/inst1/Scripts/test.sh > /home/inst1/Scripts/test.log 2>&1

.个人资料:

[..whatever..]
PATH=/tmp

export PATH

test.sh:

#!/usr/bin/bash

echo $PATH

cat 到 test.log 给我:

 /usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/bin/X11:/sbin:/usr/java5/jre/bin:/usr/java5/bin

我猜它与 AIX 环境有关,但我不知道 - 看起来很简单,但我在某处遗漏了一些东西。

试试这个:

* * * * * bash -c "source /home/inst1/.profile; /home/inst1/Scripts/test.sh" > /home/inst1/Scripts/test.log 2>&1

cron 默认使用 /bin/sh,而 source 不是 POSIX shell 命令。您需要使用 . 代替:

* * * * * . /home/inst1/.profile; /home/inst1/Scripts/test.sh > /home/inst1/Scripts/test.log 2>&1