A basic script would just check the zip file's size and switch zip files accordingly. Something like this:
## This counter is used to change the zip file name
## The maximum size allowed for the zip file
## The first zip file name
## Exit if the zip file exists already
if [ -f $ZIPFILE ]; then
echo $ZIPFILE exists, exiting...
## This will hold the zip file's size, initialize to 0
## Go through each of the arguments given in the command line
for var in "$@"; do
## If the zip file's current size is greater than or
## equal to $MAXSIZE, move to the next zip file
if [[ $SIZE -ge $MAXSIZE ]]; then
## Add file to the appropriate zip file
zip -q $ZIPFILE $var;
## update the $SIZE
SIZE=`stat -c '%s' $ZIPFILE`;
- The script expects files, not directories, if you want it to run on directories add
-r to the
zip command. However, it will not check the file size until each directory has been compressed.
- The zip file's size is checked after each compression. This means that you will get files that are larger then your limit. This because it is hard to guess what a file's compressed size will be so I can't check before adding it to the archive.