Cron 作业:如果从 Cron 作业运行 shell 脚本,if/else 条件不会按预期工作
我编写了以下 shell 脚本:
#!/bin/bash
MAIL=/usr/mail/${LOGNAME:?}
. /installations/etl_scripts/etl_job.properties
JOB_LOG_FILE_PATH=$JOB_LOG_FILE_PATH
export JOB_LOG_FILE_PATH
JOB_LOG_FILE_NAME=$JOB_LOG_FILE_NAME
export JOB_LOG_FILE_NAME
JAVA_HOME=$JAVA_HOME
export JAVA_HOME
CATALINA_HOME=$CATALINA_HOME
export CATALINA_HOME
PENTAHO_HOME=$PENTAHO_HOME
export PENTAHO_HOME
PENTAHO_JAVA_HOME=$PENTAHO_JAVA_HOME
export PENTAHO_JAVA_HOME
ETL_JOB_HOME=$ETL_JOB_HOME
export ETL_JOB_HOME
ETL_SCRIPTS_HOME=$ETL_SCRIPTS_HOME
export ETL_SCRIPTS_HOME
PATH=$PATH
export PATH
# Virre ETL transformation job execution
echo $ETL_JOB_ENABLED >> /tmp/templog.log
date +"%D %r `echo Scheduled Pentaho ETL job is starting...`" >> $JOB_LOG_FILE_PATH/$JOB_LOG_FILE_NAME
if [ $ETL_JOB_ENABLED = 'Yes' ]; then
sh $PENTAHO_HOME/kitchen.sh -file $ETL_JOB_HOME/sync_job.kjb >> $JOB_LOG_FILE_PATH/$JOB_LOG_FILE_NAME
else
echo "Pentaho ETL job is dissabled. Please enable it in etl_job.properties by setting ETL_JOB_ENABLED property to yes" >> $JOB_LOG_FILE_PATH/$JOB_LOG_FILE_NAME
fi
date +"%D %r `echo Completed`" >> $JOB_LOG_FILE_PATH/$JOB_LOG_FILE_NAME
echo ----------------------------------------------------------------- >> $JOB_LOG_FILE_PATH/$JOB_LOG_FILE_NAME
当我从控制台运行它时,if/else 语句按预期工作。但是,当它从计划的 Cron 作业运行时,它会挂在 if 语句中或之前的某个位置:它成功地将 if 语句之前的消息写入日志文件,之后什么也没有发生。
有什么解决方案可以解决这个问题吗?
I wrote the following shell script:
#!/bin/bash
MAIL=/usr/mail/${LOGNAME:?}
. /installations/etl_scripts/etl_job.properties
JOB_LOG_FILE_PATH=$JOB_LOG_FILE_PATH
export JOB_LOG_FILE_PATH
JOB_LOG_FILE_NAME=$JOB_LOG_FILE_NAME
export JOB_LOG_FILE_NAME
JAVA_HOME=$JAVA_HOME
export JAVA_HOME
CATALINA_HOME=$CATALINA_HOME
export CATALINA_HOME
PENTAHO_HOME=$PENTAHO_HOME
export PENTAHO_HOME
PENTAHO_JAVA_HOME=$PENTAHO_JAVA_HOME
export PENTAHO_JAVA_HOME
ETL_JOB_HOME=$ETL_JOB_HOME
export ETL_JOB_HOME
ETL_SCRIPTS_HOME=$ETL_SCRIPTS_HOME
export ETL_SCRIPTS_HOME
PATH=$PATH
export PATH
# Virre ETL transformation job execution
echo $ETL_JOB_ENABLED >> /tmp/templog.log
date +"%D %r `echo Scheduled Pentaho ETL job is starting...`" >> $JOB_LOG_FILE_PATH/$JOB_LOG_FILE_NAME
if [ $ETL_JOB_ENABLED = 'Yes' ]; then
sh $PENTAHO_HOME/kitchen.sh -file $ETL_JOB_HOME/sync_job.kjb >> $JOB_LOG_FILE_PATH/$JOB_LOG_FILE_NAME
else
echo "Pentaho ETL job is dissabled. Please enable it in etl_job.properties by setting ETL_JOB_ENABLED property to yes" >> $JOB_LOG_FILE_PATH/$JOB_LOG_FILE_NAME
fi
date +"%D %r `echo Completed`" >> $JOB_LOG_FILE_PATH/$JOB_LOG_FILE_NAME
echo ----------------------------------------------------------------- >> $JOB_LOG_FILE_PATH/$JOB_LOG_FILE_NAME
When I run it from console, if/else statements work as expected. But when it was ran from scheduled Cron job, it hangs somewhere in or before if statement: It successfully writes message before if statement to log file and after that nothing happens.
Any solutions how to resolve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试删除 kitchen.sh 文件的扩展名并添加 sh 的完整路径:
You can try to remove extension for kitchen.sh file and also add full path to sh :