8

I have a legacy Java program that outputs an SQL script. I then use Apache Derby to run that SQL on the target database (which is not on the same server as CRON).

When run via putty, this works fine. When run in windows this works fine. When run using CRON, Derby reads £ signs as ?.

If I look at the sql script generated (using VI), it contains the £ signs. If I check the database however, it contains ?.

Why would running this under CRON make the program behave any differently?

2 Answers 2

6

It appears that CRON was the issue. When the Java program ran, and outputted the results to file, it failed to write correctly. The SQL file I was reading was pointing at a wrong version.

To solve the problem, I added the following code near the top of the CRON script

export LANG = en_US.UTF-8

This ensured that the £ sign was correctly formatted.

2
  • You can also accept your own answers (clicking on the tick in the circle left to your answer). :)
    – htorque
    Nov 12, 2010 at 5:16
  • My cron script didn't know what "export" command is. LANG=de_DE.UTF-8 LANGUAGE=de LC_ALL=de_DE.UTF-8 (each in new line) worked for me
    – RadekR
    Dec 28, 2022 at 10:15
4

for me, the mentioned solutions weren't working. another solution i read was to set

"LANG=en_US.UTF-8" in the "/etc/environment" file.

But wasn't working neither.

What was working for me was to open the crontab file with

crontab -e

and set at the beginning:

LANG=de_DE.UTF-8
LANGUAGE=de
LC_CTYPE=de_DE.UTF-8
PYTHONIOENCODING=utf8

Which also sets the environment variable.

This must be done with every user you want to run these variables. For root run "sudo -s" before entering crontab.

1
  • Shouldn't you set "LANG=de_DE.UTF-8" in the "/etc/environment" file? instead of US for Deutsch?
    – RadekR
    Dec 28, 2022 at 10:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .