我有一个用于发送通知的 shell 脚本。 shell 脚本可以通过 CLI 手动运行,但当放入 crontab 时,它不会执行其结束任务。
更具体地说,我通过将输出从 crontab 发送到 cron.log
来逐行检查脚本,该日志给出了预期的输出。但通过 java 命令发送通知的最终任务在 crontab 中仍然不起作用。
我已经检查了所有可能的条件,但不知道我缺少什么,请帮忙。
定时任务:
* * * * * bash absolute_path/script.sh > abolutepath/pushNotCron.log
shell 脚本:
#!/bin/bash
if [ condition ]
then
some code ........
java -jar $absPath/$jarFileName "argument"
fi
脚本中没有错误
最佳答案
问题是,当您通过 cron 启 Action 业时,默认创建的 shell 是使用最小环境创建的。要看到这一点,请尝试运行一个仅显示所有环境变量(包括 PATH)的 cron 作业。
解决这个问题的一些常见方法是:
1) 通过运行 .profile 来启动所有 cron 脚本
2) 显式调用所需的“.profile”,因此:
* * * * * bash ./.profile ; Absolute_path/script.sh > abolutepath/pushNotCron.log
3) 有一个特殊的 cron-wrapper 脚本 - 请参阅 https://stackoverflow.com/a/41756145/681444
关于java - shell脚本从crontab调用,但脚本中的结束任务没有被执行,但手动它可以工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58424246/