Results 1 to 6 of 6

Thread: Hi, my batch file operation is failing. Can you check my CLI command.

  1. #1
    Join Date
    Apr 2009
    Beans
    Hidden!

    Hi, my batch file operation is failing. Can you check my CLI command.

    Here is my command. It does not work. Possibly because of the dollar signs? I am not to familiar with stringing commands together very well. I pieced this together based on tidbits from all over the web. It is calling up the Imagemagick command convert to do operations on 39 PNG files and output the new files in a separate dir.

    Code:
    find ./ -name  *.png -exec convert  {} -shave 50x50 -bordercolor white -border 1x1 -fuzz 70% -trim /home/nate/Pictures/trim/{} \;

  2. #2
    Join Date
    Apr 2012
    Beans
    7,256

    Re: Hi, my batch file operation is failing. Can you check my CLI command.

    What dollar signs are you referring to? Can you be more specific than "it does not work"? Do you get an error message? Are the files converted but the output goes somewhere else?

    FWIW I'd probably wrap the convert function in a shell scriptlet e.g.

    Code:
    find ./ -name  '*.png' -exec sh -c '
      convert  "$1" -shave 50x50 -bordercolor white -border 1x1 -fuzz 70% -trim "/home/nate/Pictures/trim/${1##*/}"
    ' sh {} \;
    or

    Code:
    find ./ -name  '*.png' -exec sh -c '
      for f; do convert  "$f" -shave 50x50 -bordercolor white -border 1x1 -fuzz 70% -trim "/home/nate/Pictures/trim/${f##*/}"; done
    ' sh {} +
    Last edited by steeldriver; October 18th, 2016 at 07:48 PM.

  3. #3
    Join Date
    Apr 2009
    Beans
    Hidden!

    Re: Hi, my batch file operation is failing. Can you check my CLI command.

    Quote Originally Posted by steeldriver View Post
    What dollar signs are you referring to? Can you be more specific than "it does not work"? Do you get an error message? Are the files converted but the output goes somewhere else?

    FWIW I'd probably wrap the convert function in a shell scriptlet e.g.

    Code:
    find ./ -name  '*.png' -exec sh -c '
      convert  "$1" -shave 50x50 -bordercolor white -border 1x1 -fuzz 70% -trim "/home/nate/Pictures/trim/${1##*/}"
    ' sh {} \;
    Tried that one and it did nothing. Just went back to the prompt. Using mine it just does the same thing, no output and no files created. Is there a certain way these should be typed in. I just type them in manually and double check them too. I also copied and paste and that did not work well.

  4. #4
    Join Date
    Apr 2012
    Beans
    7,256

    Re: Hi, my batch file operation is failing. Can you check my CLI command.

    What do you get when you just do

    Code:
    find ./ -name  '*.png'
    If there were no error messages, then it usually indicates that the command executed successfully - but that's its definition of successful, which might not necessarily be yours - for example it will "successfully" not convert any files if there are in fact no files matching the *.png pattern

  5. #5
    Join Date
    Oct 2013
    Location
    Colorado
    Beans
    560
    Distro
    Xubuntu 20.04 Focal Fossa

    Re: Hi, my batch file operation is failing. Can you check my CLI command.

    Quote Originally Posted by MechaMechanism View Post
    Here is my command. It does not work. Possibly because of the dollar signs? I am not to familiar with stringing commands together very well. I pieced this together based on tidbits from all over the web. It is calling up the Imagemagick command convert to do operations on 39 PNG files and output the new files in a separate dir.

    Code:
    find ./ -name  *.png -exec convert  {} -shave 50x50 -bordercolor white -border 1x1 -fuzz 70% -trim /home/nate/Pictures/trim/{} \;
    The problem is that {} in the find command contains the full path down to wherever the png file is. For example something like
    Code:
    /home/nate/Pictures/vacation/2014-bermuda/scuba01.png
    The command is trying to write an output file to something like
    Code:
    /home/nate/Pictures/trim/./home/nate/Pictures/vacation/2014-bermuda/scuba01.png
    which fails because several directory levels are missing

    What you need is commands that use the full path of the png files for input, but only use the filename part for output. Try this:

    Code:
    while IFS= read -r -d '' file; do
      filename=`basename "$file"`
      convert "$file" -shave 50x50 -bordercolor white -border 1x1 -fuzz 70% -trim "/home/nate/Pictures/trim/$filename"
    done < <(find ./ -name "*.png" -print0)
    This syntax makes the find command print null delimited lines for each png found enabling the while loop to handle filenames that contain spaces or special characters.

  6. #6
    Join Date
    Apr 2009
    Beans
    Hidden!

    Re: Hi, my batch file operation is failing. Can you check my CLI command.

    Ha, Ha, Ha. I had accidentally renamed the png files simply numbers. So I renamed the files again with .png. Everything work now.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •