I am running a script intended to resize all images in a folder and its subdirectories if the dimensions are of a certain size. The script hangs on the "convert" line after getting through about 1,000-2,000 images. (The exact image it hangs on is different every time).
#! /bin/bash
for f in $(find . -wholename "./raw/*.jpg"); do
# fwidth, fheight, outputdir, filename variables defined...
if [ "$fwidth" -gt 1000 ] || [ "$fheight" -gt 1000 ]; then
convert -resize 60% -quality 92 -unsharp 0x0.5 $f ${outputdir}/${filename};
else
cp $f ${outputdir}/${filename};
fi
done
First of describe in more detail what "hanging" means. Does it stop execution? Does convert
work at 100% CPU usage for some time? Something else?
Then start debugging the script. Please add some debugging output and try to run the script with bash -x script.sh
which should output all commands actually ran.
#! /bin/bash
for f in $(find . -wholename "./raw/*.jpg"); do
echo "=========== processing file $f"
# fwidth, fheight, outputdir, filename variables defined...
if [ "$fwidth" -gt 1000 ] || [ "$fheight" -gt 1000 ]; then
convert -verbose -resize 60% -quality 92 -unsharp 0x0.5 $f ${outputdir}/${filename};
else
cp -v $f ${outputdir}/${filename};
fi
done
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.