单独执行.sh文件正常,在crontab定时任务中配置执行失败
#!/bin/bash
# 定时任务执行失败添加以下俩行
source /etc/profile
source ~/.bash_profile
# 替换为实际脚本逻辑...
echo "abc"
文章描述了一个问题,即.sh脚本在单独执行时正常,但在Cronjob的定时任务中配置执行时遇到问题,怀疑是由于没有正确加载环境变量文件(如/etc/profile和~/.bash_profile)。
单独执行.sh文件正常,在crontab定时任务中配置执行失败
#!/bin/bash
# 定时任务执行失败添加以下俩行
source /etc/profile
source ~/.bash_profile
# 替换为实际脚本逻辑...
echo "abc"
33万+
1361