I have this single threaded working code which I want to convert it as multi-threaded.
The below script is started with the variable userThread which will accept the number of threads as parameter. Then it should work as per the number of threads specified while running the program.
The code reads an Input ImageURLs file having single column values like
100049/65994/640x480/ALTMA_EXCLUSIVE_ACERO_2013_11.JPG
100049/65994/640x480/ALTMA_EXCLUSIVE_ACERO_2013_12.JPG
100049/65994/640x480/ALTMA_EXCLUSIVE_ACERO_2013_13.JPG
and tries to upload it to a location (for different sizes declared in the "IMAGE_SIZES" variable.
I want to know how I can make this as a multi-threaded program.
Code:
. /etc/profile
. /root/.bash_profile
userThread=$1
IMAGE_SIZES=640x480,400x300,160x120,80x60,220x170,110x85,220x140
IMAGES_HOME="/inventory/"
BUCKET="s3://assets.domain-name.com"
local_path="/websites/admin.domain-name.com/ROOT/uploads/inventory/"
for size in $(echo $IMAGE_SIZES | tr "," " ")
do
echo "Now checking images directory of $size"
while read image; do
DealerMain=$(awk -F/ '{ print $1}' <<<"${image}")
DealerSub=$(awk -F/ '{ print $2}' <<<"${image}")
imagename=${image##*/}
s3cmd put --recursive --force "$local_path$DealerMain/$DealerSub/$size/$imagename" "$BUCKET$IMAGES_HOME$DealerMain/$DealerSub/$size/"
done < /root/cronjobs/ImageURLs.txt
done
echo "Completed !"
Thanks in advance.
Regards
Praveen