What isn't working right with the find
command you posted when run from Jamf Pro?
Hi wmehilos. Thank you for responding to my post.
I'm not sure what's not working, but I can tell you when I test the script via Self Service, nothing is deleted.
But if I run the command to list the files via terminal:
find ~/.trash -mindepth 1 -mtime +60 -ls
I can see the files that command will delete.
The problem is your use of ~
to the path to the home directory. ~/.Trash
evaluates to the home of the user running the command, and when that script gets run from Jamf, it evaluates to the root account, meaning ~/.Trash
, becomes /private/var/root/.Trash
and not the logged in user's Trash as you're expecting it to.
You have to get the current user's username, and use that as part of the full path for it to work.
Try this instead:
#!/bin/sh
current_user=$(scutil <<< "show State:/Users/ConsoleUser" | awk '/Name
&& ! /loginwindow/ {print $3}')
find /Users/${current_user}/.Trash -mindepth 1 -mtime +60 -delete
mm2270 is correct, but I fear also his solution will not help on Macs running 10.15, as the .Trash appears to be out of reach for the shell:
find: /Users/thisuser/.Trash: Operation not permitted
Automation on macOS becomes more and more difficult. Soon the macOS will be so secure that it is useless :(
@mschroder Is that error coming from when the command is run out of a Jamf policy? Because I'm not seeing that issue myself. Can you elaborate on what happened?
If have several devices on which the shell has no permission to access .Trash. I have not tried via jamf, but only locally, with and without sudo. On some nodes it was fine, on others it failed. Strange thing is that 'ls -l@d ~/.Trash' shows no extended attribute, which is what I expected to find.
Thank you, mm2270! The script worked.
Thank you, everybody, for your time.
If have several devices on which the shell has no permission to access .Trash. I have not tried via jamf, but only locally, with and without sudo. On some nodes it was fine, on others it failed. Strange thing is that 'ls -l@d ~/.Trash' shows no extended attribute, which is what I expected to find.
I know this is an old post but I came across the same issue. Make sure that the app running the script has full disk access (in my case CodeRunner)