Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I've generated a shell script that uses ImageMagick to convert and crop around 18000 images. Here's a sample entry (so there are 18000 of these):

if [ ! -f ./cropped/16333-1.png ]
then
convert -crop 724x118+876+1989 ./lin/34.png ./cropped/16333-1.png
echo cropping 16333-1
fi
if [ ! -f ./cropped/16333-1_thumb.png ]
then
convert -define jpeg:size=400x100 ./cropped/16333-1.png -thumbnail '400x100>' -background transparent -gravity center -extent 400x100 ./cropped/16333-1_thumb.png
echo thumbing 16333-1
fi

The script only runs for about 2000 images before hanging forever. Am I missing something, or leaking memory somewhere?

Thanks for your help!

UPDATE

I tried running the script with the -x flag as suggested, and the script hung after this command:

+ '[' '!' -f ./cropped/8967-1_thumb.png ']'
+ convert -define jpeg:size=400x100 ./cropped/8967-1.png -thumbnail '400x100>' -background transparent -gravity center -extent 400x100 ./cropped/8967-1_thumb.png

However, when I interrupt the script and then copy and paste the command above, it runs just fine. No hanging. I can then resume the script, and it sets off again fine.

Mysterious...

share|improve this question

1 Answer 1

My guess is that there's some shell meta character in there somewhere which is tripping it up.

To diagnose and solve:

  1. Identify exactly where it stops
  2. Look at the ten lines around it
  3. Look for any > < ! $ which aren't escaped

Alternately, add -x to the first line of the script so that you can see each command as it's run. It should look something like:

#! /bin/bash -x
share|improve this answer
    
I agree. It sounds like the script was generated from a list of filenames, so the problem may originate from a funny character (><!$ as you say, or maybe even just a space) in a filename. The +x option should make this much easier to diagnose. –  Gordon Davisson Dec 29 '10 at 16:48
    
Thanks! You're right that it was generated (from a range of numbers, not from a list of filenames). However when I try using the -x flag, it seems to fail on a command that then works OK. Please see update. –  AP257 Dec 29 '10 at 17:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.