Created
March 16, 2016 01:23
-
-
Save dhiva/3b2637a27f9ff4ca6ed0 to your computer and use it in GitHub Desktop.
Shell script to split file for multipart upload
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
FILE=$1 | |
FILESIZE=$(stat -c%s "$FILE") | |
BLOCK_SIZE=10000 | |
BLOCKS=$(((FILESIZE + (BLOCK_SIZE + 1)) / BLOCK_SIZE)) | |
echo "$FILESIZE" | |
echo "$BLOCKS" | |
for (( block = 0; block < $BLOCKS; block += 1 )) | |
do | |
echo $block; | |
START_RANGE=$((block*BLOCK_SIZE)) | |
END_RANGE=$((((block +1) * BLOCK_SIZE) - 1)) | |
if [ "$block" -eq $((BLOCKS-1)) ] | |
then | |
END_RANGE=$FILESIZE | |
fi | |
echo "$START_RANGE : $END_RANGE" | |
dd if=$FILE skip=$block bs=$BLOCK_SIZE count=1 status=noxfer 2> /dev/null > "files/img$block" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment