Crontab 没有按预期工作

Crontab not working as expected

#/bin/bash
cd /home/oracle/scripts/mon_scripts/
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
export ORACLE_SID=test
cat /dev/null > /home/oracle/scripts/mon_scripts/wget_cache.out
a=`sqlplus test/test123@/home/oracle/scripts/mon_scripts/flushtable.sql|grep -A 2 COUNT|tail -n1`
if [ $a == 0 ];then
(
echo "Empty- Nothing Processed"
)
else
(
echo "localhost" >> wget_cache.out
ssh localhost wget http://localhost/cs/ContentServer?pagename=debug/ReloadRefData -O - >> wget_cache.out
echo "--------------" >> wget_cache.out
echo "localhost" >> wget_cache.out
wget http://localhost:7005/cs/ContentServer?pagename=debug/ReloadRefData -O - >> wget_cache.out
echo "--------------"
echo "localhost" >> wget_cache.out
wget http://localhost:7005/cs/ContentServer?pagename=debug/ReloadRefData -O - >> wget_cache.out
sqlplus test/test123 @/home/oracle/scripts/mon_scripts/deletetable.sql
)
fi

以上脚本在命令提示符下运行良好,但使用 crontab 时无法运行 - 请建议,在 crontab 中,似乎条件不工作。

Crontab 不会执行与您的用户具有相同环境变量的作业。

所以它不知道在哪里寻找二进制文件(PATH 没有定义不同)。您必须只使用绝对路径而不是相对路径来执行命令。

例如,将 wget 替换为 /usr/bin/wget