split shell script

You know there are split (binary) program under linux that can split your file (binary or text) into some file with option you can pass to. I am not going to discuss it. and to combine them you can use cat program, I am not going to discuss it either. but you can search the google how to use split and combine the splitted file with cat.

And now my problem is I need to split a file then combine them using the same option over and over which make me bored. That''s why I created this small shell script which split the file, remove the file and automatically create another shell script to combine the splitted file.

The script will split the input file into smaller file (1 MB each) in this case so I can copy the file into floppy disk, you can change the split parameter on this line:
split -d -b 1000000 $1 $1.
I assume 1MB is 1 million byte to change it just change 1000000 with other number you want.
usage example:
$ ./xsplit.sh myfile.tar.gz
then it will create the following file
myfile.tar.gz.00
myfile.tar.gz.01
myfile.tar.gz.02
..
myfile.tar.gz.99
joinmyfile.tar.gz.shx
myfile.tar.gz.md5

myfile.tar.gz.00 until myfile.tar.gz.99 is the splitted file. myfile.tar.gz.md5 is the md5sum of the original file which needed for checking the integrity of the file after combined. joinmyfile.tar.gz.shx is the shell script for combining file myfile.tar.gz.00 until myfile.tar.gz.99

To join those file run
$ ./joinmyfile.tar.gz.shx

Below is the script:



#------------------------------------------------------------------------------------
#xsplit.sh
echo "split and join script"
if [ "$1" == "" ]; then
echo "usage ./xsplit.sh "
else
if [ -e $1 ]; then
echo "Processing, please wait..."
echo "Filename : $1"
echo "MD5SUM : `md5sum $1`"
echo "md5sum result is saved into file $1.md5 for compare after join"
md5sum $1 > $1.md5
split -d -b 1000000 $1 $1.
echo "Deleting source file..."
rm -i $1
echo "To join the splits files use this following command:"
echo "./join$1.shx"
#--- create a shell script to join splitted files ---#
touch join$1.shx
echo "cat $1.?? > $1" >> join$1.shx
echo "rm -f $1.??" >> join$1.shx
echo "md51=\\`md5sum $1\\`" >> join$1.shx
echo "md52=\\`cat $1.md5\\`" >> join$1.shx
echo "if [ \\"\\$md51\\" == \\"\\$md52\\" ]; then" >> join$1.shx
echo " echo \\"File matches\\"" >> join$1.shx
echo " else" >> join$1.shx
echo " echo \\"File doesn''t matches or md5sum file is missing\\"" >> join$1.shx
echo "fi" >> join$1.shx
chmod +x join$1.shx
#--- done ---#
else
echo "File not exist, please verify!"
fi
fi
#----------------------------------------------------------------------------------------------