Thanks for all your work on this, Gerry. I'll have to study it and learn from it. Mike On Thu, 14 Oct 2010, Gerry wrote: > Here it is a bit better (shorter and more quotes and no backticks.) > The creation of the empty splitmbox file is unnecessary if you do the cat > before the check. > And you can just touch the count file and it'll work fine. > > Like this: > > #! /bin/sh -f > prefix="splitmbox" > # 10MB > maxsize=10000000 > > # set a variable to the contents of the count file > touch count > count=$(expr $(cat count) + 0) > > # append whatever came into this script to the splitmbox file > cat >> "$prefix.$count" > > # if the size is greater than your max, then increment count > if [ $(stat -c %s "$prefix.$count") -gt $maxsize ] ; then > expr $count + 1 > count > echo "Splitting to $prefix.$(cat count)" > fi > #-----------------End Script > > > > On Thu, 14 Oct 2010, Gerry wrote: >> #! /bin/sh -f >> >> prefix=splitmbox >> # 10MB >> maxsize=10000000 >> >> #check that the count file exist. Make one if it doesn't. >> if [ ! -f count ] ; then >> echo 1 > count >> fi >> >> # set a variable to the contents of the count file >> count=$(cat count) >> >> # create a splitmbox file if it doesn't exist >> if [ ! -f $prefix.$count ] ; then >> touch $prefix.$count >> fi >> >> #check the size of that box >> size=`stat -c %s $prefix.$(cat count)` >> >> # if it's greater than your max, then increment count >> if [ $size -gt $maxsize ] ; then >> count=$(expr $count + 1) >> echo $count > count >> echo "Splitting to $prefix.$count" >> fi >> >> # append whatever came into this script to the splitmbox file >> cat >> $prefix.$count >> #-----------------End Script >> >> Then I ran >> procmail -s ./maxmail.sh < mbox >> >> >> if you have some really large individual mails, they will stay together >> and may make your split mbox bigger than your max. >> My result: >> Splitting to splitmbox.2 >> Splitting to splitmbox.3 >> Splitting to splitmbox.4 >> Splitting to splitmbox.5 >> >> gsker at veeta:~/mail> ls -l splitmbox.* >> -rw-rw-r-- 1 gsker gsker 10006881 2010-10-14 19:44 splitmbox.1 >> -rw-rw-r-- 1 gsker gsker 11950245 2010-10-14 19:45 splitmbox.2 >> -rw-rw-r-- 1 gsker gsker 12995777 2010-10-14 19:45 splitmbox.3 >> -rw-rw-r-- 1 gsker gsker 10063591 2010-10-14 19:45 splitmbox.4 >> -rw-rw-r-- 1 gsker gsker 4328906 2010-10-14 19:45 splitmbox.5 >> >> gsker at veeta:~/mail> wc -l splitmbox.* >> 165330 splitmbox.1 >> 210013 splitmbox.2 >> 200543 splitmbox.3 >> 171013 splitmbox.4 >> 90904 splitmbox.5 >> 837803 total >> >> gsker at veeta:~/mail> wc -l mbox >> 837803 mbox >> >> >> >> >> Cool! >> >> >> >> > > -- > Gerry Skerbitz > gsker at skerbitz.org