Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

In FC10, ls outputs dates in 'YYYY-MM-DD HH:MM' format when called by command line or script. When called by cron, the dates are in format 'Mon DD HH:MM'.

What gives? why the change? I've checked env and alias, and nothing was obviously different between the shell and cron.

share|improve this question

3 Answers 3

up vote 2 down vote accepted

The date format depends on your locale settings ($LC_TIME, $LC_ALL, $LANG).

share|improve this answer
    
It was getting unset in /etc/profile.d/lang.sh which is run when the shell starts via: "export LC_TIME=" THANKS! –  Travis Jul 1 '10 at 9:08

There's two ways I know to fix this, at least in Ubuntu Lucid.

Add this line at the top of you crontab file.

LC_TIME="en_US.UTF-8"

Or specify the time format for ls -l in your script.

ls -l --time-style=long-iso

I like this second way because it makes the script itself more portable. Also, every time you modify the environment for a crontab, you modify the environment for all scripts running in that crontab, and possibly introduce bugs in the other scripts that way.

Paul S

share|improve this answer

Another possibility is --time-style option. It might be specified, for example, somewhere in aliases for one of the users, the one who runs cron tasks or the one who runs the script from the command line.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.