We help IT Professionals succeed at work.

Cron script not producing same date output when run manually

adamshields asked
The following commands are part of a script. When run from a cron task I get a different output for the date.

From user of BASH -rw-r--r-- 1 user user 199M 2010-05-10 06:00 /home/user/backups.tar.gz
From cron user of SH -rw-r--r-- 1 user user 199M May 10 06:00 /home/user/backups.tar.gz

The consistencies in the date formatting are a problem for the script. Is there a way to force ls to produce a specific date string such as the first one regardless of the shell or user?
/usr/bin/find / -type f -size +20M -exec /bin/ls -lh {} \; 2> /dev/null | /usr/bin/awk '{ print $8 ": " $5 }' >> /tmp/update2.log

Open in new window

Watch Question

Frank ContrepoisVP Technical Sales

put the line in an executable file and start the file with the line


Tried that and also tried specifying the shell in the crontab per this doc: http://www.novell.com/coolsolutions/feature/11582.html
Most Valuable Expert 2013
Top Expert 2013

Do you use "/bin/ls -lh" in both cases?
VP Technical Sales
ls -l --time-style="+%b %_d %Y

            with -l, show times using style STYLE: full-iso, long-iso,  iso,
            locale,  +FORMAT.   FORMAT is interpreted like `date'; if FORMAT
            is FORMAT1<newline>FORMAT2, FORMAT1 applies to non-recent  files
            and FORMAT2 to recent files; if STYLE is prefixed with `posix-',
            STYLE takes effect only outside the POSIX locale
Frank ContrepoisVP Technical Sales

nice feature of ls. I love to learn and to help at the same time :-)