0

When I run the following command from my script file it gives me:

find: missing argument to `-exec'

But the same command from the command line works normally:

find /home/poseidoncharters/poseidon_backup/*.sql -mtime +1 -exec rm -f {} \;

I run the script like ./myscript.sh

Sean Bright
  • 118,630
  • 17
  • 138
  • 146
  • There is no obvious error here. Do you run the command exactly as visible here? – tripleee Dec 18 '19 at 16:00
  • Use `-delete` instead of `-exec` – Sean Bright Dec 18 '19 at 16:05
  • Debugging steps to try: (1) Run `type -a find` both at the command line and in the script, to see if you're calling the same `find` program both times. (2) Prepend `printf '<%s> '` to the command in the script, to see how the shell is expanding the command. – ruakh Dec 18 '19 at 16:06
  • Check for DOS line endings; the last argument is probably `;\r`, not `;`. – chepner Dec 18 '19 at 16:09
  • 1
    Unrelated, but use `find /home/poseidoncharters/poseidon_backup -name '*.sql' ...` instead. – chepner Dec 18 '19 at 16:11

1 Answers1

1

Well as other said on their comment command seems correct, and it was. the problem i was having was newline character problem, as i wrote this script in windows machine and then uploaded to unix server, so as soon as i ran dos2unix remove_backup.sh it started to work.

  • BTW, (1) this is the very first thing in the "before asking about problematic code" section of https://stackoverflow.com/tags/bash/info; (2) as a general practice consider using `bash -x yourscript` to trace the commands your script runs when debugging; in this case, you would see `$';\r'` instead of `\;` or `';'`, lett you know something's up. – Charles Duffy Dec 18 '19 at 16:29