Matter with cron

Hello

I run on Freenas 7.2.
I want to run a script in cron.
But a part of my script return false computing when it turn on cronjob.
You can see the problem line on my crontab file.

Next my crontab file:

Code:
SHELL=/bin/sh
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin
HOME=/var/log
#
#minute hour    mday    month   wday    who     command
#
# Perform email status report.

54 12 * * * root find /mnt/data/home -mtime 1 -type f -exec ls -as {} \; | grep "dom_" | awk '{ SUM += $1} END { print SUM/1024/1024 }' >> /root/log/tata.txt

when I execute the line directly in commande line, It display a good result and
When I execute the line whith cron, it display a false result (It multiply by two the Good result)

Perhaps anyone have meet this problem

Thanks RAF
 
Maybe a shell quoting issue. You really should be putting that into a shell script and calling the script from cron instead.
 
Thanks aragon,

I try too with a shell script, but I have the same problem.

I continue to search for.

RAF
 
Your block size is not set. From the ls(1) manpage:

Code:
     -s      Display the number of [b]blocks[/b] used in the file system by each
             file....

Then further below:
Code:
     [b]The default block size is 512 bytes.[/b]  The block size may be set with
     option -k or environment variable BLOCKSIZE.  Numbers of blocks in the
     output will have been rounded up so the numbers of bytes is at least as
     many as used by the corresponding file system blocks (which might have a
     different size).

Information for using -k:
Code:
     -k      This has the same effect as setting environment variable
             BLOCKSIZE to 1024, except that it also nullifies any -h options
             to its left.

If you look in your interactive shell, you will see that your BLOCKSIZE environment variable is set to 'K.' Your easiest solution is to add -k to your ls(1) invocation:
Code:
54 12 * * * root find /mnt/data/home -mtime 1 -type f -exec ls -ask {} \; | grep "dom_" | awk '{ SUM += $1} END { print SUM/1024/1024 }' >> /root/log/tata.txt
 
Back
Top