Kyle
Kyle

Reputation: 979

Weird Cron ls Behavior

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?

Upvotes: 1

Views: 190

Answers (2)

dsolimano
dsolimano

Reputation: 8986

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

Upvotes: 3

Łukasz
Łukasz

Reputation: 36191

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

$ LC_ALL="locale name" your-script

Upvotes: 3

Related Questions