3

We are trying unsuccessfully to run a java command in the following shell script:

#!/bin/bash
/usr/java/jdk1.8.0_91/bin/java -jar /home/cyberren/cyberren/cyberexe/D50_1_Migration.jar > d50Migration.log

We call it with the following line in our cron file:

45 08 * * * /home/cyberren/queries/d50migration.sh

We have confirmed that the shell script runs via cron, but it doesn't execute the java. It tries, but our log output is just this one line:

2016-Jun-30 08:58:11 - D50_1_Migration Process v104

We expect many more lines following such as this:

2016-Jun-30 08:58:11 - D50_1_Migration Process v104
2016-Jun-30 08:58:11 - migrateData -> SQL: UPDATE D50_1 SET xassessment = 192, iStepsTotal = 9 WHERE xIndx = 128
2016-Jun-30 08:58:11 - migrateData -> SQL: UPDATE D50_1 SET xassessment = 192, iStepsTotal = 9 WHERE xIndx = 129
...

We are able to run the same shell script manually, and it executes the java. We are also able to execute the java line manually, and it runs correctly.

So to repeat:

  • The cron job runs as scheduled
  • The shell script runs
  • The log is created, but only with the initial line
  • The java line in the shell script does not run
  • Both the shell script and the standalone java line run manually successfully
  • We have confirmed all directories referenced

Thanks in advance for the thoughts and advice.

Updates/Additional Info:

  • (Edit) Permissions are correct
  • (Edit) Tried adding a preceding cd "$(dirname "$0")" line per Alex's advice. Same output.

Solution:

  • @Jackson, you probably don't have access to the source code for the jar file, so debugging would be fruitless. Try setting up the cron job so that it is called from a bash login and sends STDERR output to STDOUT and logs both in a file, this should do it, 45 08 * * * /bin/bash -l -c "cd /home/cyberren/queries; ./d50migration.sh 2&>1 |tee -a /home/cyberren/d50migration.log" this way you should get to see all output and error output generated (if any) – Finbarr O'Brien 22 mins ago
  • At first we were pretty happy to have a way to look at our errors, but your cron line successfully ran the .jar! You've solved our problem and given us a way to successufully schedule and run java archive files via cron.
13
  • 1
    Hi ! You can try to add mode debug lines in your jar in order to see where it bugs Commented Jul 1, 2016 at 13:13
  • @Jägermeister Permissions are good! We confirmed with the same user via PuTTY. Commented Jul 1, 2016 at 13:17
  • @Jérèm Does it make sense that it would bug when run via cron but not when run manually? Commented Jul 1, 2016 at 13:18
  • Based on the fact that you get a line in the log, either the java program exits prematurely, or has hung somewhere. Are there any occurrances of the java process if you do ps -fu cyberren (assuming your user is 'cyberren')? I would suggest to try step debugging with your favourite IDE through the java code by adding debug parameters to the java command such as: -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=7777 and see where it fails Commented Jul 1, 2016 at 13:20
  • Hint: never put more information into comments; update your question instead. Commented Jul 1, 2016 at 13:21

1 Answer 1

4

Try setting up the cron job so that it is called from a bash login and sends STDERR output to STDOUT and logs both in a file, this should do it:

45 08 * * * /bin/bash -l -c "cd /home/cyberren/queries; ./d50migration.sh 2>&1 |tee -a /home/cyberren/d50migration.log" 

this way you should get to see all output and error output generated (if any)

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks again! Made an aggravating Friday into a nice start to the holiday weekend
I think it should be 2>&1 instead of 2&>1. (SO wouldn't let me edit only 2 characters in the answer.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.