简体   繁体   中英

Something wrong with my crontab?

I am going to create a crontab task to schedule my task.

My /etc/crontab looks like this,

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
17 15 * * * root sh /opt/app/tool/ReviewSummaryTool/runf.sh

The task script runf.sh has content looks like this,

#!/usr/bin/env bash

java -Dhostname=$(hostname) -jar ReviewSummaryTool.jar -full

But the crontab task could not be executed (I checked the output log) when time is arrived.

However, the task script could be execute by command below,

sh /opt/app/tool/ReviewSummaryTool/runf.sh

And I checked the log of crontab at /var/log/cron and it seems that the task has already been executed. See brief log content below,

Aug 31 15:17:01 SSECBIGDATA01 crond[1677]: (*system*) RELOAD (/etc/crontab)
Aug 31 15:17:01 SSECBIGDATA01 CROND[29248]: (root) CMD (sh /opt/app/tool/ReviewSummaryTool/runf.sh)

Now, I have no idea what's wrong with my configuration. My operating system is CentOS.

Any help would be appreciate. Thanks in advance.

For debugging purposes replace sh with /bin/sh -vx in the crontab entry:

 17 15 * * * root /bin/sh -vx /opt/app/tool/ReviewSummaryTool/runf.sh

Then the trace of the executed script will be printed, so emailed to you.

And add logger commands inside your runf.sh script, eg have it be

 #!/bin/sh
 logger -t runfjob start of runf pid $$ in $(pwd) on host $(hostname)
 java -Dhostname=$(hostname) -jar ReviewSummaryTool.jar -full
 logger -t runfjob end of runf pid $$

The logger command makes entries to the system log using syslog(3) . You should find these messages under /var/log , perhaps in /var/log/messages or /var/log/syslog etc...

I strongly suggest to put the full path of the ReviewSummaryTool.jar file in the java command of your runf.sh script. It is likely that your cronjob is run in a current directory not having that file. Or perhaps put a cd command before the java one.

Be sure that the $PATH is correct and that java is found there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM