【问题标题】:Path not get set from crontab未从 crontab 设置路径
【发布时间】:2015-11-12 09:12:42
【问题描述】:

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

crontab:

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

.profile:

[..whatever..]
PATH=/tmp

export PATH

test.sh:

#!/usr/bin/bash

echo $PATH

cat to test.log 给了我:

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

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

【问题讨论】:

    标签: bash crontab aix


    【解决方案1】:

    试试这个:

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

    【讨论】:

    • 谢谢。你能解释一下解决方案和尊重(为什么以我的方式不起作用)..?
    • 那么sourcesh中的等价物是什么?
    • source 切换到. 解决了这个问题而不使用bash -c "..."
    • 好吧,奇怪。也许是 AIX 的 sh 的一个特性。
    • sh 不知道source,但如果sh 实际上是指向shell 的链接,例如bash,你仍然可以使用source。 POSIX 等效项是 .(只是一个句点)。
    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 2012-03-03
      • 1970-01-01
      • 2014-10-27
      • 1970-01-01
      • 1970-01-01
      • 2012-04-25
      • 2019-12-14
      • 2013-06-06
      • 1970-01-01
      相关资源
      最近更新 更多