du(1) result different in a cronjob

Hello.

I have a strange problem.
This is my script:
Code:
/bin/sh
du -s /bin
du -sh /bin

When I run this script (as root), I have:
Code:
992     /bin
992K    /bin

Ok, that's normal. But when I insert this script in my root cronjob, like this:
Code:
*      *       *       *       *       /test

I have:
Code:
1984	/bin
992K	/bin

Is anybody could explain me why 'du -s' returns different values. This is the same directory, the same script. The first is run manually, the second in a cronjob.

I don't have the problem with 'du -sh'.

Thanks a lot.

Regards,
 
Code:
#!/bin/sh

BLOCKSIZE=1k
du -s /bin
du -sh /bin

returns:
Code:
1984	/bin
992K	/bin
 
clinty said:
Code:
#!/bin/sh

BLOCKSIZE=1k
du -s /bin
du -sh /bin

returns:
Code:
1984	/bin
992K	/bin

Almost correct. You are setting BLOCKSIZE in the parent process -- the shell that runs the du commands -- but this setting is not visible to the child processes. Try this instead:

Code:
#!/bin/sh

BLOCKSIZE=1k ; export BLOCKSIZE

du -s /bin
du -sh /bin

This should work slightly better, and you won't have to set 'BLOCKSIZE' in each command invocation that needs it.
 
Back
Top