-1

I am creating the script below in cronjob. It is manually getting generated. But, when in cron, it is failing to generate the files.

Below is my unix cron script.

#!/usr/local/bin/bash
var=`perl -w -e '$d=1*86400;@t=localtime (time -$d); printf "%.2d%.2d%.2d", $t[5]+1900,$t[4]+1,$t[3];'`

var="`echo $var |cut -c3-8`"

i=1;

while [ $i -le 8 ]
do

    cd /home/svfe/bin
    ./bills_unloader -d $var -f $i
    i=`expr $i + 1`
done

echo "Done !

When I try to debug the script, I am finding below error.

/usr/lib/hpux64/dld.so: Unable to find library 'libclntsh.so.11.1'. /home/swa/swa2/autoload/bills_unloader.sh: line 19: 7078 Killed
./bills_unloader -d 170606 -f $i

Why is the command failing in cron, but working fine when executed manually?

ArturFH
  • 1,697
  • 15
  • 28
swwapnil
  • 1
  • 4
  • 1
    Did you see the excellent debugging advice in the [crontab tag wiki](https://stackoverflow.com/tags/cron/info)? – Benjamin W. Jun 07 '17 at 14:29
  • @BenjaminW. It seems this debugging advice is, how to say that, a little bit recursive at the very moment. – ArturFH Jun 12 '17 at 08:05
  • @ArturR.Czechowski That is a shame. The crontab tag wiki was an excellent debugging guide, but it's synonymized to "cron" now. Has been since January 16, apparently, which is strange – I'm sure I've seen the debugging guide more recently than that. – Benjamin W. Jun 12 '17 at 13:30
  • Here is the [archived tag wiki](https://web.archive.org/web/20160804040638/http://stackoverflow.com/tags/crontab/info). – Benjamin W. Jun 12 '17 at 13:34
  • @BenjaminW. I\ve just asked on meta if it's possible to restore lost wiki: https://meta.stackoverflow.com/questions/350576/it-is-possible-to-restore-wiki-of-tag-aliased-to-another-tag – ArturFH Jun 12 '17 at 13:37

2 Answers2

1

Most probably you have LD_LIBRARY_PATH variable set in your CLI environment, but it is not available when script is run under cron. Add a line:

declare -x > /tmp/variables.log.$(date +%s).$$

at the beginning of the script, the compare the logs from manual run and cron run. If necessary, set the LD_LIBRARY_PATH properly in your script.

As it is a hpux system, it could be also SHLIB_PATH.

ArturFH
  • 1,697
  • 15
  • 28
0

You might be using command with another user and crontab with another. Suppose your command is working fine with user "xyz" try below command in your crontab entry - su - xyz -c sh