tags:

views:

53

answers:

2

I have a Python script that is running a few ls commands. This script runs under cron all day. I use awk to write out the column that the filename is in when ls -l is executed.

When I run the script via command line the output looks like this

-rw-rw---- 1 mysql adm       141 2010-03-25 08:56 mysql-bin.000485
-rw-rw---- 1 mysql adm       141 2010-03-25 09:01 mysql-bin.000486
-rw-rw---- 1 mysql adm      5073 2010-03-25 09:31 mysql-bin.000487

but when I run the scrupt under cron as root, the output looks like this

-rw-rw---- 1 mysql adm       141 Mar 25 10:07 mysql-bin.000488
-rw-rw---- 1 mysql adm       141 Mar 25 10:22 mysql-bin.000489
-rw-rw---- 1 mysql adm        98 Mar 25 10:22 mysql-bin.000490

That makes awk return the wrong column. Is there anyway to get the date to format the same under cron?

+3  A: 

Problem is with different locales between your account and root. You can change them temporarily by:

$ LC_ALL="locale name" your-script
Łukasz
+3  A: 

If you're on GNU ls, you can pass --time-style=long-iso. More formats are here.

dsolimano
That worked like a charm! Thanks.
Kyle Terry