[K12OSN] script help - please (GOT IT)

Jimmy Schwankl schwankl at chatham.k12.nc.us
Tue May 25 14:24:10 UTC 2004


On May 25, 2004, at 9:11 AM, Jimmy Schwankl wrote:

> Hello good people.  I can't get the syntax right on a script I'm 
> working on.  I need to delete a directory's contents when it's size 
> gets over a certain amount.  I know this should be uber-easy, but I 
> just can't get it.  Here's what I have so far:
>
> #!/bin/tcsh
> # get the size of the directory
> du -ks /savedHomedirs/
> # if total is over 100MB, then clear out directory
> if ($1>100000) then
> rm -rf /savedHomedirs/*
> endif
>
> #exit 0
> exit 0

I got it to work.  Here's what I ended up with: (I switched to bash)

#!/bin/bash
# get the size of the directory
size=$(du -ks /savedHomedirs/ | awk '{print $1}')
# if total is over 100MB, then clear out directory
if  [ $size -gt 100000 ]
then
rm -rf /savedHomedirs/*
fi

#exit 0
exit 0

Peace,
Jimmy





More information about the K12OSN mailing list