0

Am trying to create one and add the same to the cron. This is the commands I am trying to run through the script.

#!/bin/bash
find . -mmin -60 -name "*.jpg" $(printf "! -name %s " $(cat processed.txt) ! -name cache) -exec convert -resize 1000x800 -quality 85% {} {};
find  -mmin -60 -type f -name "*.jpg" -exec basename {} \; &> processed.txt

f I am running these commands directly on shell, I don't get any error. but if say I have stored this in a file called compress and run the script as ./compress I get the error -

find: missing argument to `-exec'

what mistake I am making and how I can fix that.

10
  • You have two find commands, both having the -exec option. Which of them fail? Commented Jan 30, 2019 at 14:21
  • cannot say - on the console only it prints the error I have written. as I have tried taking out each statement one by one and there is no error. when both lines are present then only it is throwing the error. Commented Jan 30, 2019 at 14:23
  • Could it have something to do with one find missing a path to search in? Perhaps it's the missing backslash before the semicolon to terminate the -exec in the first find command? Commented Jan 30, 2019 at 14:26
  • Hmm. I added the backslash as you suggested and run the commnd agin, but still the same error. Commented Jan 30, 2019 at 14:27
  • Also, how about the order of the commands? The second command creates the file processes.txt which the first command uses... Commented Jan 30, 2019 at 14:28

1 Answer 1

1

Build an array of arguments for the first find command instead of relying on the command substitution.

while IFS= read -r line; do
  processed+=(! -name "$line")
done < processed.txt

Your immediate problem, though, is that you forgot to escape the semicolon so that it would be treated as an argument to find, rather than a command terminator.

find . -mmin -60 -name "*.jpg" "${processed[@]}"  \
  ! -name cache  -exec convert -resize 1000x800 -quality 85% {} {} \;
#                                                                  ^^
find  -mmin -60 -type f -name "*.jpg" -exec basename {} \; &> processed.txt
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Chepner. This works perfect. where I can have reference for building this shell script?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.