Strange behaviour with perl i/o?

Hi All,
I got a strange problem here. I have a perl script which is fetching data from a database table and writing a file with that data.

       If i run that script from linux command line, the file it creates is a normal ascii text file without any binary character in it.But if i run it the same script through crontab, it is creating a data file with some binary characters appended in the data.

      Did anybody faced this kind of situation before? Please help me if so?
      Thanks in Advance!

Version Information:

Linux: Debian Kernel 2.6.26-1-amd64
Perl v5.10.0

Regards
Dileep

Are you using the same shell while running the script? Please check that and see

cheers,
Devaraj Takhellambam

Thanks for your response devtakh.

I checked the SHELL env variable and it says /bin/bash.
So it will be used while executing the script from command line and from cron, right?

Regards
Dileep

I'd check environmental variables under cron .
pay special attention to IFS , PATH , LD_LIBRARY , and PERL*
set in crontab :
min hour * * * env > /tmp/env
and examine /tmp/env

You got it right mate!

I did what you had suggested and got the below:

SHELL=/bin/sh
PATH=/usr/bin:/bin
PWD=/home/dileepp
SHLVL=1
HOME=/home/dileepp
LOGNAME=dileepp
_=/usr/bin/env

So the shell is different while executing the script from cron.
Can you advise me how i can set it a particular shell so as the cron to use it
while executing a script?

Regards
Dileep

I am not sure that difference between bash and sh ( BTW check what really /bin/sh is ! It can be link ) will garble your output .

Try giving /bin/bash scriptname while defining in the crontab file and see if that helps.

Yes, what you doubted is right, it's a link.

/bin/sh -> bash

So it's not the one which mess up my output. My mind is above the charset defined for crontab execution and the normal ones. I am not pretty sure this is the key and if that is where these are defined. Any idea?

Try putting

. ~/.profile

at the beginning of your script.

I can't see a .profile file in my home. What's the code or settings to be done inside the .profile file if an creating one in my home?

---------- Post updated at 08:24 AM ---------- Previous update was at 05:08 AM ----------

Hi Guys,
I identified the problem, the problem is due to the incorrect value for the variable 'LC_CTYPE' in crontab's environment which deals with charset conversions.

I added the line in the file /etc/environment

LC_CTYPE="en_AU.UTF-8"

for the crontab to use it while executing scripts. It will have the same effect, if we add this line into /etc/security/pam_env.conf file as well.

The crontab will pick up env settings from these two files.

Thanks for all your help, much appreciated.

Regards
Dileep