PDA

View Full Version : du(1) result different in a cronjob


clinty
March 6th, 2009, 12:33
Hello.

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

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

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

I have:
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,

ale
March 6th, 2009, 12:34
Try setting the BLOCKSIZE variable to 1k

clinty
March 6th, 2009, 12:41
#!/bin/sh

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

returns:
1984 /bin
992K /bin

ale
March 6th, 2009, 12:51
Sorry, I'm really busy.
What with
BLOCKSIZE=1k du -s /bin

clinty
March 6th, 2009, 12:55
Yeah, it works! Thanks a lot!

keramida@
March 7th, 2009, 03:30
#!/bin/sh

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

returns:
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:


#!/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.