# du(1) result different in a cronjob



## clinty (Mar 6, 2009)

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 (Mar 6, 2009)

Try setting the BLOCKSIZE variable to 1k


----------



## clinty (Mar 6, 2009)

```
#!/bin/sh

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

returns:

```
1984	/bin
992K	/bin
```


----------



## ale (Mar 6, 2009)

Sorry, I'm really busy.
What with 
BLOCKSIZE=1k du -s /bin


----------



## clinty (Mar 6, 2009)

Yeah, it works! Thanks a lot!


----------



## keramida@ (Mar 7, 2009)

clinty said:
			
		

> ```
> #!/bin/sh
> 
> BLOCKSIZE=1k
> ...



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.


----------

