Script to remove MacOS High Sierra Install.app from applications folder

jstine
Contributor

Hello,

Can anyone tell me why this script will not work when deployed through the JSS?

rm -Rf /Applications/Install macOS High Sierra.app

I've also tried:

rm -Rf "/Applications/Install macOS High Sierra.app"

When I run these commands in terminal, it works fine. When I push these commands as scripts through the JSS, they do nothing.

Any ideas?

21 REPLIES 21

Cornoir
Contributor II

Why not use the Restricted Software option on the JSS, you can stop the app process as well as delete the app.

mm2270
Legendary Contributor III

Can't really see a reason why it wouldn't work. It looks right to me from here.
But can you try adding in the full path to rm, like /bin/rm ? It really shouldn't need that, but try it anyway.

emily
Valued Contributor III
Valued Contributor III

Can you post the entire script? Or are you using the Execute Command option on a policy?

ammonsc
Contributor II

would it work if it was this way

rm -rf /Applications/"Install macOS High Sierra.app"

jstine
Contributor

@Cornoir I"m pushing the latest version of the installer to all of our machines. I want to remove any installers that may have been previously downloaded from the app store by users.

@mm2270 Will try that now.

@emily That is the entire script. I've tried both ways that I posted as a script. Have not tried running with Files and Process Execute Command. I kind of need it ran as a script so that I can run it before other actions without creating two policies.

emily
Valued Contributor III
Valued Contributor III

@jstine if it's a bash script you need to add #!/bin/bash to the top of the script.

ammonsc
Contributor II

I think you will need to edit the script to setup the beginning

#!/bin/sh

rm -rf /Applications/"Install macOS High Sierra.app"

exit

jstine
Contributor

@mm2270 No luck using /bin/rm

@ammonsc Tried your suggestion, but no resolve :(

jstine
Contributor

@ammonsc Tried #!/bin/sh and #!bin/bash. Still nothing.

@emily I tried that too but still no luck. I appreciate the suggestions though!

ammonsc
Contributor II

is the policy giving you an error in the log? That may help to figure out the problem.

mm2270
Legendary Contributor III

Ah. So strangely enough, in the past, scripts without a shebang in them would work when run from the Jamf console. We actually had a few back in the day, and they never had a problem running interestingly enough. I assume, at least back then, that the console would read the script extension (.sh), and assume a bash script and execute it correctly. That may have changed with version 9 or 10 though. Especially now that scripts can be created directly in the web UI and don't need any extension.

I made an incorrect assumption that the script line was being added to the Execute Command field, not run as a full script, given it's a single line. Because as a single command in Execute Command, it would have worked as is.

jstine
Contributor

Removed.

jstine
Contributor

I think something might be wrong with our JSS. The logs show that the script isn't actually being run as a part of the policy.

mm2270
Legendary Contributor III

I would assume something is wrong with the policy first before assuming it's your whole Jamf Pro setup. Create a new policy and maybe even a new script and put them together and try it again.
And just a question, but, the policy IS running, correct? This isn't a case of the policy not running again because of the policy blackout window is it?

jstine
Contributor

@mm2270 Yes the policy is running. I completely deleted and recreated both the policy and the script. When looking at the logs, it does not actually run the script at all. I've opened a case with Jamf support and hope to hear something soon.

Thank you everyone for your help. I will post the resolution when I have it.

ICTMuttenz
Contributor

We use this script:

sudo rm -rf "/Applications/Install macOS High Sierra.app"

mpenrod
New Contributor III

I am using a policy and under "Files and Processes" I am searching for file by path and checked delete if found. I think this was a user requested feature a few revs back.

Look
Valued Contributor III

Maybe the script has an operating system requirement set in it's options, check the Limitations tab in the script editor.
You didn't copy another script to initially get started?

jhalvorson
Valued Contributor
#!/bin/sh

## set the name of the appication to remove
appName="/Applications/Install macOS High Sierra.app"


logFile="/private/var/log/TECHUninstalls.log"

log () {
    /bin/echo $1
    /bin/echo $(date "+%Y-%m-%d %H:%M:%S: ") $1 >> $logFile 
}

log "-----"
log "If found, will remove $appName..."

if [ -d "$appName" ]
    then
        /bin/rm -rf "$appName"
        log "Removed $appName"
    else
        log "$appName wasn't there."
fi

jtrant
Valued Contributor

I'm not sure why it's necessary to remove the old installer, since any time I've pushed an updated version to clients it overwrites the old one.

rstasel
Valued Contributor

Sorry for the necromancy, but we're seeing users updating using old cached installers... I'd just nuke them all from orbit, but I worry about trying to delete the old one when it's being run. 

Anyone have a good way to check if it's running at all before just deleting it?