linux - Crontab 没有按预期工作

标签 linux shell cron

#/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

关于linux - Crontab 没有按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28850691/

相关文章:

Python 获取 'permission denied' 到 Linux 中的文件

python - Paramiko ssh linux 命令执行没有结果

linux - 在类 unix 环境中从 shell 获取人类友好的文件大小 [可移植性]

shell - 从 zip 文件中提取文件并在编辑后将其放回 zip 文件的最佳方法

php - AJAX - 执行的 shell 命令的进度条

java - 立即启动并在一定时间间隔后运行的 cron 触发器

linux - erlang:UNIX 域套接字支持?

c - 如何在 SIGABRT 信号处理程序中等待

php - 如何在 Cpanel 中使用 Cron 处理发送电子邮件限制?

php - 给定日期的预定数据库更新 - MySQL 和 PHP