<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.appian.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>KB-1136 Cleanup script fails to run when executed via cron job</title><link>https://community.appian.com/support/w/kb/357/kb-1136-cleanup-script-fails-to-run-when-executed-via-cron-job</link><description /><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>KB-1136 Cleanup script fails to run when executed via cron job</title><link>https://community.appian.com/support/w/kb/357/kb-1136-cleanup-script-fails-to-run-when-executed-via-cron-job</link><pubDate>Fri, 24 Feb 2017 14:44:18 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:2378ea3a-80aa-4705-937e-2e4d984494cc</guid><dc:creator>Nick Vigilante</dc:creator><comments>https://community.appian.com/support/w/kb/357/kb-1136-cleanup-script-fails-to-run-when-executed-via-cron-job#comments</comments><description>Current Revision posted to Appian Knowledge Base by Nick Vigilante on 2/24/2017 2:44:18 PM&lt;br /&gt;
&lt;div class="row content_container"&gt;
&lt;h2 id="symptoms"&gt;Symptoms&lt;/h2&gt;
&lt;p&gt;The &lt;strong&gt;cleanup.sh&lt;/strong&gt; script doesn&amp;rsquo;t work when being executed from the cron tab. When it is executed manually, the files get cleaned up normally as expected.&lt;/p&gt;
&lt;h2 id="cause"&gt;Cause&lt;/h2&gt;
&lt;p&gt;This is caused by the script picking up an incorrect &lt;code&gt;JAVA_HOME&lt;/code&gt; or &lt;code&gt;PATH&lt;/code&gt; if there are multiple versions of Java installed.&lt;/p&gt;
&lt;h2 id="action"&gt;Action&lt;/h2&gt;
&lt;p&gt;There are three possible solutions to this problem. The first should be to remove the old versions of Java and update both the &lt;code&gt;PATH&lt;/code&gt; and &lt;code&gt;JAVA_HOME&lt;/code&gt; variable to ensure that the right value gets picked up. If this still doesn&amp;rsquo;t address it, one can use either of the following solutions.&lt;/p&gt;
&lt;h4 id="set-the-java_home-variable-in-the-crontab-file"&gt;Set the JAVA_HOME variable in the crontab file&lt;/h4&gt;
&lt;p&gt;The cron job would look like the following:&lt;/p&gt;
&lt;pre&gt;$ crontab -l
JAVA_HOME=/PATH_TO_JAVA_HOME
* * * * * /../../../cleanup.sh
&lt;/pre&gt;
&lt;h4 id="set-the-java_home-variable-in-the-script-itself"&gt;Set the JAVA_HOME variable in the script itself&lt;/h4&gt;
&lt;ol&gt;
&lt;li&gt;Create a copy of the &lt;code&gt;cleanup.sh&lt;/code&gt; script.&lt;/li&gt;
&lt;li&gt;Modify the cleanup script to export &lt;code&gt;JAVA_HOME&lt;/code&gt;:&lt;br /&gt;
&lt;pre&gt;#!/bin/bash
pushd &lt;code&gt;dirname $0&lt;/code&gt; &amp;gt; /dev/null
. exports.sh
. exports-ant.sh
export JAVA_HOME=/PATH_TO_JAVA_HOME
&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;Change your crontab to run the modified cleanup script and verify that it works correctly.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;In the two methods above, you have to modify the &lt;code&gt;/PATH_TO_JAVA_HOME&lt;/code&gt; value to the actual path of the most updated Java installation.&lt;/p&gt;
&lt;h2 id="affected-versions"&gt;Affected Versions&lt;/h2&gt;
&lt;p&gt;This article applies to all versions of Appian using Linux as the OS.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Last Reviewed:&amp;nbsp;February 2017&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;

&lt;div style="font-size: 90%;"&gt;Tags: administration, scripts&lt;/div&gt;
</description></item></channel></rss>