0

I seeking help for to setup a periodical job on my imac with macOS Big Sur v11.4. What I want to do, is to delete all contents of a given folder every 60 seconds with a bash or zsh script. It doesn't matter which one. Default for terminal is set to zsh. Therefore I tried it with zsh.

My current approach is to have two files. A zsh script which deletes the folder contents and for 'launchd' I have a plist which periodically should calls the script.

If I call the zsh script in terminal it works fine and deletes the folder contents. But when it is called by launchd it returns with "no matches found" and I don't know where the problem is.

Therefore it would be very kind, if someone can help me with this.

/Library/LaunchDaemons/com.deleteGCODE.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.deleteGCODE.plist</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/local/bin/deleteGCODE.sh</string>
    </array>
    <key>StartInterval</key>
    <integer>60</integer>
    <key>StandardErrorPath</key>
        <string>/tmp/mycommand.err</string>
    <key>StandardOutPath</key>
        <string>/tmp/mycommand.out</string>
</dict>
</plist>

/usr/local/bin/deleteGCODE.sh:

#!/bin/zsh
dir="/Users/simon/Documents/Simplify3D/GCODE/"
rm -rf "$dir"*

the output of /tmp/mycommand.out:

/usr/local/bin/deleteGCODE.sh:3: no matches found: /Users/simon/Documents/Simplify3D/GCODE/*

p.s. I am very sorry that I have postet my previous message in the wrong section. Hopefully this time it is correct.

Miracuru
  • 65
  • 6
  • Are there any files in the directory when the script is run? – Shawn Jul 17 '21 at 23:50
  • 1
    And if not, do you have the NOMATCH option turned on? – Shawn Jul 17 '21 at 23:51
  • This has nothing to do with standalone-vs-cron, but with how `zsh` handles globs that don't match any files. You'll get the same error if you run the script manually when the directory is empty. – chepner Jul 18 '21 at 12:23
  • Does this answer your question? [Why zsh tries to expand \* and bash does not?](https://stackoverflow.com/questions/20037364/why-zsh-tries-to-expand-and-bash-does-not) – chepner Jul 18 '21 at 12:24
  • Thanks for you'r hellp all. I didn't had turned NOMATCH on but it is now, with setopt +o nomatch. Now the error isn't visible due to that. but the files aren't deleted. The folder isn't empty. – Miracuru Jul 19 '21 at 09:32
  • @chepner : I think in the case of `$dir*` (Quoting is IMO not necessary here), zsh should expand as well. At least mine does. – user1934428 Jul 22 '21 at 14:05
  • @Miracuru : Are you sure that you don't mean `rm -rf $dir/*` ? – user1934428 Jul 22 '21 at 14:06

0 Answers0