开发者

Weird Cron ls Behavior

开发者 https://www.devze.com 2022-12-24 08:35 出处:网络
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.

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 cro开发者_如何转开发n 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?


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


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

$ LC_ALL="locale name" your-script
0

精彩评论

暂无评论...
验证码 换一张
取 消