Posted on 01-24-2023 01:21 PM
Hi,
I have just run into this issue recently whereby I try to remove vulnerable apps that are not installed to /Applications folder but copied and being run from Desktop or Downloads folders.
Tried this easy command in terminal locally and worked like charm:
rm -R ~/Downloads/Visual_Studio_Code.pkg
So then I created a policy that would use a script with the same exact command to remove the file and ended up having this:
Script result: rm: /var/root/Downloads/Visual_Studio_Code.app: No such file or directory
Cannot I just use tilde for specifying the currently logged in user's Download folder? Why does it say /var/root?
I have 100+ users and not fancy writing a separate script for each of them where I just use the full path.
I'm sure I'm overlooking some obvious scripting rules here so all advice would be greatly appreciated!
Solved! Go to Solution.
Posted on 01-24-2023 02:08 PM
Using ~ specifies the working directory and causes issues when Jamf runs the script as root. I tend to use full paths.
The following variable will specify the current user.
currentUser=$(/bin/ls -l /dev/console | /usr/bin/awk '{print $3}')
Making your command look like this.
rm -R /Users/$currentUser/Downloads/Visual_Studio_Code.pkg
Posted on 01-24-2023 02:08 PM
Using ~ specifies the working directory and causes issues when Jamf runs the script as root. I tend to use full paths.
The following variable will specify the current user.
currentUser=$(/bin/ls -l /dev/console | /usr/bin/awk '{print $3}')
Making your command look like this.
rm -R /Users/$currentUser/Downloads/Visual_Studio_Code.pkg
Posted on 01-27-2023 03:27 AM
Hi!
Thanks for the tip! It worked perfectly fine.
Appreciate it!