Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cronjob of python script removing commas 4

Status
Not open for further replies.

AnotherAlan

Technical User
Feb 10, 2006
362
0
0
GB
Hi,

I have a python script that produces a report detailing amounts.
When run from the command line it produces the report in the correct format. When run from con it omits the commas.

I'm guessing that this has something to do with the shell it runs under, however, I have tested this from csh,sh, bash and ksh and the output is consistent across all of them.

Any other ideas please?

Thanks
 
Hi Feherke, thanks for the quick reply;

The python script is over 500 lines long but the most pertinent part of it is this;

Code:
 def convert(value,dttype=STR_TYPE):
    321     if dttype==AMT_TYPE: # make sure to format it as 100,000,000.00
    322         return locale.format('%d', value, grouping=True)
    323     elif dttype==PERCT_TYPE:
    324         return str(int(round(value)))+"%"
    325     else:
    326         return str(value)
[/code/

The script is called via another script;

[code] #!/bin/sh

LOCATION=London
EMAIL_TO="<list of emails>"

fill_file=`ls /app/logs/loonix/Fills-*.log | head -n1`
tick_file=`ls /app/logs/loonix/Ticks-*.log | head -n1`

echo "Using fills file $fill_file"
echo "Using ticks file $tick_file"

python /app/razr/fxagg/bin/generate_fill_report.py -f $fill_file -t $tick_file -l $LOCATION -e "$EMAIL_TO"

And the crontab is;

07 09 * * 1,2,3,4,5 cd /app/razr/fxagg/bin;./send_report_for_london.sh >> /app/logs/loonix/auto.out

I have tried using #!/usr/bin/python at the top of the pythin script and also tried removing it. Either way it does not seem to make any difference.

Appreciate the help.
Alan

 
Hi

Alan said:
I have tried using #!/usr/bin/python at the top of the pythin script and also tried removing it. Either way it does not seem to make any difference.
Pointless here. The interpreter specified in the shebang is used only if the script was started as standalone executable : /scriptfile.py vs. python /scriptfile.py. If the script file is specified as parameter for an interpreter, the shebang will not be evaluated.

Regarding the comma, are you talking about the CSV field separator or the decimal separator ? In the later case I would take a look at the locale settings. That usually differs in [tt]cron[/tt]'s environment.


Feherke.
 
Check the value of the locale environment variables (LANG,LC_*) in send_report_for_london.sh.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks Guys,

Cron is using POSIX values. I'll use an environment file to change these.
 
Hmmm, may need some further assistance here. I've tried changing the locale settings in the wrapper script send_report_for_london.sh but its still not working.

Code:
#!/bin/bash

LANG="en_GB.UTF-8"
LC_CTYPE="en_GB.UTF-8"
LC_NUMERIC="en_GB.UTF-8"
LC_TIME="en_GB.UTF-8"
LC_COLLATE="en_GB.UTF-8"
LC_MONETARY="en_GB.UTF-8"
LC_MESSAGES="en_GB.UTF-8"
LC_PAPER="en_GB.UTF-8"
LC_NAME="en_GB.UTF-8"
LC_ADDRESS="en_GB.UTF-8"
LC_TELEPHONE="en_GB.UTF-8"
LC_MEASUREMENT="en_GB.UTF-8"
LC_IDENTIFICATION="en_GB.UTF-8"


LOCATION=London
EMAIL_TO="email list"

fill_file=`ls /app/logs/loonix/Fills-*.log | head -n1`
tick_file=`ls /app/logs/loonix/Ticks-*.log | head -n1`

echo "Using fills file $fill_file"
echo "Using ticks file $tick_file"

python /app/razr/fxagg/bin/generate_fill_report.py -f $fill_file -t $tick_file -l $LOCATION -e "$EMAIL_TO"

Am I doing this correctly?
 
export the variables.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks again Gents, this has now worked perfectly.
If I could award more stars I would.

Appreciate all the help.
Alan
 
Just for good order I found a solution to put in the python script;

def main(argv):
locale.setlocale(locale.LC_ALL, 'en_US')

Thanks
 
Just because you can't award more stars, Alan, doesn't mean someone else can't - this is useful stuff!

The internet - allowing those who don't know what they're talking about to have their say.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top