# Shell script with Java code in Cron

**URL:** <https://community.unix.com/t/shell-script-with-java-code-in-cron/338674>\
**Category:** Shell Programming and Scripting\
**Created:** [January 15, 2014, 8:00am UTC](https://community.unix.com/t/shell-script-with-java-code-in-cron/338674 "2014-01-15T08:00:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Deei](https://community.unix.com/letter_avatar/deei/32/6_22734026db12803ebb3e059622ac3534.png) [@Deei](https://community.unix.com/u/Deei)\
**Post date:** [January 15, 2014, 8:00am UTC](https://community.unix.com/t/shell-script-with-java-code-in-cron/338674/1 "2014-01-15T08:00:17Z")

</div>

Dear All,

I have a shell script which has JAVA code inside it runs perfectly on command line. But while I set it on cron, all rest of the script runs but Java code doesnt.

```nohighlight
java -cp "lib/common-client.jar:lib/commons-beanutils-1.7.0.jar:lib/commons-betwixt-0.8.jar:lib/commons-collections-3.1.jar:lib/commons-collections-
3.2.jar:lib/commons-configuration-1.2.jar:lib/commons-dbcp-1.2.1.jar:lib/commons-dbcp-1.2.2.jar:lib/commons-digester-1.7.jar:lib/commons-io-1.2.jar:
lib/commons-io-1.3.1.jar:lib/commons-lang-2.1.jar:lib/commons-lang-2.2.jar:lib/commons-logging-1.0.4.jar:lib/commons-logging-1.1.jar:lib/commons-log
ging-adapters-1.1.jar:lib/commons-logging-api-1.1.jar:lib/commons-net-1.4.0.jar:lib/commons-pool-1.2.jar:lib/jconn3.jar:PDL.jar:." com.local.myPDWriter

```

Can you please help me out if I need to set JAVA path or any other file while setting up on cron ?

---

<div class="post-metadata">

**Author:** ![vbe](https://community.unix.com/user_avatar/community.unix.com/vbe/32/266_2.png) [@vbe](https://community.unix.com/u/vbe)\
**Post date:** [January 15, 2014, 8:41am UTC](https://community.unix.com/t/shell-script-with-java-code-in-cron/338674/2 "2014-01-15T08:41:18Z")

</div>

Set the environment properly in the shell script ( e.g. path to java... etc...) at the beginning and it will work

---

<div class="post-metadata">

**Author:** ![Deei](https://community.unix.com/letter_avatar/deei/32/6_22734026db12803ebb3e059622ac3534.png) [@Deei](https://community.unix.com/u/Deei)\
**Post date:** [January 20, 2014, 7:00am UTC](https://community.unix.com/t/shell-script-with-java-code-in-cron/338674/3 "2014-01-20T07:00:36Z")

</div>

I have csh as default shell and writting a bash script. When I run the script from command like (csh), its running file.  
But not from cron.

Can I source .csh in bash script ?

---

<div class="post-metadata">

**Author:** ![vbe](https://community.unix.com/user_avatar/community.unix.com/vbe/32/266_2.png) [@vbe](https://community.unix.com/u/vbe)\
**Post date:** [January 20, 2014, 9:53am UTC](https://community.unix.com/t/shell-script-with-java-code-in-cron/338674/4 "2014-01-20T09:53:36Z")

</div>

If you use csh as default shell why not write your script so it uses csh and then at the beginning of your script you dont forget to add the source instruction...
