Hi Imran, $HOSTNAME is not POSIX[1], so depending on the shell being used it is present in the environment or not. bash[2] defines it other shells might not. If you're running the cron process under another user their shell might be used.
Perhaps it would be easier to try `InetAddress.getLocalHost().getHostName()` or have a look at some of the solutions offered on stackoverflow[3]. zoran [1] https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html [2] https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Bash-Variables [3] https://stackoverflow.com/questions/7348711/recommended-way-to-get-hostname-in-java On Wed, Nov 13, 2019 at 8:54 PM Imran Raza Khan <[email protected]> wrote: > > I have one jar file which contain camel route to run it from cron job i > created shell script > > public void process(Exchange exchange) throws Exception > { > String host = > exchange.getContext().resolvePropertyPlaceholders("{{env:HOSTNAME}}"); > } > > test.sh > #!/bin/sh > java -jar my.jar > > Now when i run > > sh test.sh it is able to access environment variable, but when i run from > cron job it throw null pointer exception for {{env:HOSTNAME}} > > Following is my cron > > cat > /etc/cron.d/reboot << EOF > * * * * * root /usr/bin/flock -w 1 -E 0 /tmp -c /test.sh 2>&1 | > /usr/bin/tee /dev/tty1 > EOF -- Zoran Regvart
