KB-1136 Cleanup script fails to run when executed via cron job

Symptoms

The cleanup.sh script doesn’t work when being executed from the cron tab. When it is executed manually, the files get cleaned up normally as expected.

Cause

This is caused by the script picking up an incorrect JAVA_HOME or PATH if there are multiple versions of Java installed.

Action

There are three possible solutions to this problem. The first should be to remove the old versions of Java and update both the PATH and JAVA_HOME variable to ensure that the right value gets picked up. If this still doesn’t address it, one can use either of the following solutions.

Set the JAVA_HOME variable in the crontab file

The cron job would look like the following:

$ crontab -l
JAVA_HOME=/PATH_TO_JAVA_HOME
* * * * * /../../../cleanup.sh

Set the JAVA_HOME variable in the script itself

  1. Create a copy of the cleanup.sh script.
  2. Modify the cleanup script to export JAVA_HOME:
    #!/bin/bash
    pushd dirname $0 > /dev/null
    . exports.sh
    . exports-ant.sh
    export JAVA_HOME=/PATH_TO_JAVA_HOME
    
  3. Change your crontab to run the modified cleanup script and verify that it works correctly.

In the two methods above, you have to modify the /PATH_TO_JAVA_HOME value to the actual path of the most updated Java installation.

Affected Versions

This article applies to all versions of Appian using Linux as the OS.

Last Reviewed: February 2017

Related
Recommended