3

I am writing up a script to delete folders and files based on their age to be run as a scheduled task on a Synology Diskstation box running the Busybox shell. The error I keep getting appears to relate to the FIND command and its associated EXEC call on the same line, as this shell does not seem to like the \; notation I have seen suggested elsewhere on this forum, so I tried using the single-quote format at the end of the line, and still no go.

The exact error message I see when I try to run the script as root user via SSH is this: find: -exec CMD must end by ';'

Here is the script:

#!/bin/bash
# Define a timestamp function
timestamp() {
  date +"%T"
}
#Run the job
[ -t 0 ] || exec >> "/volume1/homes/JSmo/Scripts/tmp/daily_purge_script.log" 2>&1
echo "Beginning folder delete task at: $(timestamp)"
find "/volume1/Synology Backup/CloudStation/jfs02/Local_copy_jfs02_f_drv/WindowsImageBackup/jfs02/Backup"/* -mtime +30 -exec rm -rf {} ';'
echo "Folder delete job completed at: $(timestamp)"
exit 0

I have looked at a number of solutions for this issue and tried many combinations of the syntax but could I have missed something simple here??

Thanks

EDIT

Thanks to eagle-eyed comment by @WalterA, I am adding this here for others. If you have this error please check your end of line (EOL) setting if using a text editor like NotePad++ on a Windows system and make sure it is set to Unix/OSX instead of DOS/Windows. See screenshot below for how to do this: Changing the EOL setting in NotePad++

  • Thanks for trying @Cyrus but @chepner is correct, and both variants gave me the same error. I even tried to insert `{}{\}` just before the `\;` but that did not help either. – UnEscapedCharacter Mar 05 '16 at 20:57
  • A combination of two things *might* explain the problem: are you really running `bash`, and does your script have DOS line endings? (Adding DOS line endings to a `bash` script causes an error earlier, but BusyBox comes with `ash` as the default shell. I don't know if `ash` would react in the same way to DOS line endings, but terminating that line with `;\r` instead of `;` would definitely be a problem for `find`.). – chepner Mar 05 '16 at 21:02
  • Good points @chepner I tried to invoke the script at the SSH shell prompt by running the `sh` command followed by the filename of the script from the directory it is in. Also tried using `ash` with same result. Running `bash` at the command line did not work as I am on a Busybox device. I created the script using NotePad++ with the Shell language turned on so that ought to avoid the DOS line ending issue. So maybe trying to run `bash` unsuccessfully is a clue here?? – UnEscapedCharacter Mar 05 '16 at 21:08
  • shell scripts on windows end with \r\n/ When you look at the bottom of your NotePad++ screen, do you see `DOS\Windows` (wrong) or `UNIX` (correct). You yan change this with `Edit / Format`. – Walter A Mar 05 '16 at 21:34
  • @WalterA you are correct! I checked the setting at the bottom of the NotePad++ screen and there it was, `DOS\Windows` so I used the **Edit -> EOL Conversion --> `Unix/OSX Format` option** and voila! I would like to mark this question as Answered so you get credit for your help, I am still finding my way around on this forum.. Thank you!!! – UnEscapedCharacter Mar 05 '16 at 21:55
  • You can delete this question, it isa duplicate. You can only accept an answer when it is posted as an answer, not a comment.I did not post my thoughts as an answer, since I was not sure it was what you wanted. Your thanks and that your problem is solved are all the credits I want. Just look around on the forum and learn a lot ! – Walter A Mar 05 '16 at 22:06
  • @chepner sorry if this is a "duplicate question" but I guess my concern is how would someone encountering this error even think to look at something like EOL handling as a possible culprit. I sincerely hope my latest edit to this question helps to clarify the matter for others in the future though! Thanks again and best regards... – UnEscapedCharacter Mar 05 '16 at 22:11
  • @WalterA thank you, will do!! :) – UnEscapedCharacter Mar 05 '16 at 22:12
  • DOS line endings are one of the first things you are supposed to check for before posting a question. There are many, many questions dealing with this on Stack Exchange. Closing as a duplicate isn't meant as a scolding; it's just a way of trying to keep the same answer from being scattered in many places. (The question I linked to was created by asker specifically to provide a canonical answer to all the mystery problems that had the same solution.) – chepner Mar 05 '16 at 22:14
  • Don't think of a duplicate as something to delete, but as a pointer to another question which already provides an answer. – chepner Mar 05 '16 at 22:15
  • @chepner that makes sense and I agree, the simpler the path to the solution from all variant starting points arising from the same root cause, the better! :) – UnEscapedCharacter Mar 05 '16 at 22:18

0 Answers0