Self Service Script failing

nmanager
New Contributor III

I have created the below script to remove all SMART Notebook software that was installed on a machine

!/bin/bash

Uninstall SMART Products

/Applications/SMART Technologies/SMART Uninstaller.app/Contents/Resources/uninstall --all 2> /dev/null

delete needed files

for USER_HOME in /Users/* do USER_UID=basename "${USER_HOME}" if [ ! "${USER_UID}" = "Shared" ]; then # Removing preference file from users' ~/Library/Preferences if [ -f "${USER_HOME}"/Library/Preferences/com.smarttech.gallery.plist ]; then rm -rf "${USER_HOME}"/Library/Preferences/com.smarttech.gallery.plist 2> /dev/null fi # Removing preference file from users' ~/Library/Preferences if [ -f "${USER_HOME}"/Library/Preferences/com.smarttech.notebook.Notebook.10.LSSharedFileList.plist ]; then rm -rf "${USER_HOME}"/Library/Preferences/com.smarttech.notebook.Notebook.10.LSSharedFileList.plist 2> /dev/null fi # Removing preference file from users' ~/Library/Preferences if [ -f "${USER_HOME}"/Library/Preferences/com.smarttech.notebook.Notebook.10.plist ]; then rm -rf "${USER_HOME}"/Library/Preferences/com.smarttech.notebook.Notebook.10.plist 2> /dev/null fi # Removing preference file from users' ~/Library/Preferences if [ -f "${USER_HOME}"/Library/Preferences/com.smarttech.Registry.plist ]; then rm -rf "${USER_HOME}"/Library/Preferences/com.smarttech.Registry.plist 2> /dev/null fi # Removing Hotsport Shield directory from users' ~/Library/Application Support if [ -d "${USER_HOME}"/Library/Application Support/Smart Technologies ]; then rm -rf "${USER_HOME}"/Library/Application Support/Smart Technologies 2> /dev/null fi # Removing Hotsport Shield directory from users' ~/Library/Application Support if [ -d "${USER_HOME}"/Library/Application Support/Smart Technologies inc ]; then rm -rf "${USER_HOME}"/Library/Application Support/Smart Technologies inc 2> /dev/null fi fi
done

I added 2> /dev/null trying to prevent the errors but that did nothing. I tried recreating the script with no change. I recreated the policy as well with no change. Every time I run the self service policy I get the following error

015-08-04 12:59:35 <com.jamfsoftware.selfservice>: Error executing Policy "Smart Uninstaller"
Error Domain=JAMFSoftware/SelfService Code=30 "The operation couldn’t be completed. (JAMFSoftware/SelfService error 30.)"
2015-08-04 12:59:35 <com.jamfsoftware.selfservice>: Self Service encountered a problem while attempting to run Smart Uninstaller. Contact your administrator.

Other scripts are running fine just this one is causing me issues
If I run this script from the command line it works fine
Even with it erring out it still works fine
Need some way to suppress the error from Self Service or stop it from happening

Thanks

10 REPLIES 10

nessts
Valued Contributor II

when you post a script clcik on the >_ icon not the " please. you will know if you have done the right thing as it will have a #!/bin/bash for you to copy over...

nmanager
New Contributor III
#!/bin/bash

#Uninstall SMART Products
/Applications/SMART Technologies/SMART Uninstaller.app/Contents/Resources/uninstall --all 2> /dev/null

# delete needed files
for USER_HOME in /Users/*
  do
    USER_UID=`basename "${USER_HOME}"`
    if [ ! "${USER_UID}" = "Shared" ]; then
       # Removing preference file from users' ~/Library/Preferences    
       if [ -f "${USER_HOME}"/Library/Preferences/com.smarttech.gallery.plist ]; then
    rm -rf "${USER_HOME}"/Library/Preferences/com.smarttech.gallery.plist 2> /dev/null
       fi
       # Removing preference file from users' ~/Library/Preferences    
       if [ -f "${USER_HOME}"/Library/Preferences/com.smarttech.notebook.Notebook.10.LSSharedFileList.plist ]; then
    rm -rf "${USER_HOME}"/Library/Preferences/com.smarttech.notebook.Notebook.10.LSSharedFileList.plist 2> /dev/null
       fi
       # Removing preference file from users' ~/Library/Preferences    
       if [ -f "${USER_HOME}"/Library/Preferences/com.smarttech.notebook.Notebook.10.plist ]; then
    rm -rf "${USER_HOME}"/Library/Preferences/com.smarttech.notebook.Notebook.10.plist 2> /dev/null
       fi
       # Removing preference file from users' ~/Library/Preferences    
       if [ -f "${USER_HOME}"/Library/Preferences/com.smarttech.Registry.plist ]; then
    rm -rf "${USER_HOME}"/Library/Preferences/com.smarttech.Registry.plist 2> /dev/null
       fi
       # Removing Hotsport Shield directory from users' ~/Library/Application Support
       if [ -d "${USER_HOME}"/Library/Application Support/Smart Technologies ]; then
    rm -rf "${USER_HOME}"/Library/Application Support/Smart Technologies 2> /dev/null
       fi
       # Removing Hotsport Shield directory from users' ~/Library/Application Support
       if [ -d "${USER_HOME}"/Library/Application Support/Smart Technologies inc ]; then
    rm -rf "${USER_HOME}"/Library/Application Support/Smart Technologies inc 2> /dev/null
       fi
    fi
done

nessts
Valued Contributor II

much better to read now, thanks.

nessts
Valued Contributor II

you might contemplate putting a set -x on line two and running the script by hand and make sure it works.
then you could put in some logger commands and print stuff out to the system.log if you get inside one of the ifs you could do

if [ -f file ]; then
 logger "found file, deleting"
 rm file
fi

I think your -rf on a plist file might be overkill, you might want to change your test from -f to -e for exists instead.

nmanager
New Contributor III

I have ran my current script by hand without issues. It goes through the uninstall process and filedirectory removals without issue. But for some reason when I run it via self service it errors out every time. Even though it errors out in self service it completes all of the steps but then when preforming clean up it fails. So it does everything its suppose to but still fails for unknown reasons.

nmanager
New Contributor III

I ran the script using Casper Remote and the initial command

/Applications/SMART Technologies/SMART Uninstaller.app/Contents/Resources/uninstall --all

Gives this error as part of its uninstall process. errors/English/Measure-errors.txt

Once that happens Casper believes the script has failed but it hasn't. I though 2> /dev/null would of stopped the reporting of the error.

Is there a way for Casper to ignore the error?

nessts
Valued Contributor II

I think the proper way to get all output to go to /dev/null is

/Applications/SMART Technologies/SMART Uninstaller.app/Contents/Resources/uninstall --all 2&>1

and maybe you had an & in your output but it got ate by the editor?

the other thing you can do is call the uninstall from another script and just exit 0 also ensure there is no extraneous output from the script that you are running and then Self Service will not error out.

nmanager
New Contributor III

That worked perfectly.

Thanks for the help.

nmanager
New Contributor III
#!/bin/bash

#Uninstall SMART Products
/Applications/SMART Technologies/SMART Uninstaller.app/Contents/Resources/uninstall --all 2&>1 /dev/null

# delete needed files
for USER_HOME in /Users/*
  do
    USER_UID=`basename "${USER_HOME}"`
    if [ ! "${USER_UID}" = "Shared" ]; then
       # Removing preference file from users' ~/Library/Preferences    
       if [ -f "${USER_HOME}"/Library/Preferences/com.smarttech.gallery.plist ]; then
    rm -rf "${USER_HOME}"/Library/Preferences/com.smarttech.gallery.plist 2> /dev/null
       fi
       # Removing preference file from users' ~/Library/Preferences    
       if [ -f "${USER_HOME}"/Library/Preferences/com.smarttech.notebook.Notebook.10.LSSharedFileList.plist ]; then
    rm -rf "${USER_HOME}"/Library/Preferences/com.smarttech.notebook.Notebook.10.LSSharedFileList.plist 2> /dev/null
       fi
       # Removing preference file from users' ~/Library/Preferences    
       if [ -f "${USER_HOME}"/Library/Preferences/com.smarttech.notebook.Notebook.10.plist ]; then
    rm -rf "${USER_HOME}"/Library/Preferences/com.smarttech.notebook.Notebook.10.plist 2> /dev/null
       fi
       # Removing preference file from users' ~/Library/Preferences    
       if [ -f "${USER_HOME}"/Library/Preferences/com.smarttech.Registry.plist ]; then
    rm -rf "${USER_HOME}"/Library/Preferences/com.smarttech.Registry.plist 2> /dev/null
       fi
       # Removing Hotsport Shield directory from users' ~/Library/Application Support
       if [ -d "${USER_HOME}"/Library/Application Support/Smart Technologies ]; then
    rm -rf "${USER_HOME}"/Library/Application Support/Smart Technologies 2> /dev/null
       fi
       # Removing Hotsport Shield directory from users' ~/Library/Application Support
       if [ -d "${USER_HOME}"/Library/Application Support/Smart Technologies inc ]; then
    rm -rf "${USER_HOME}"/Library/Application Support/Smart Technologies inc 2> /dev/null
       fi
    fi
done

Here is the final script. Works perfectly for removing all SmartBoard software

sean
Valued Contributor

If you're going to suppress errors then you could just delete without the loop?

eg:

rm -rf /Users/*/Library/Preferences/com.smarttech.gallery.plist 2> /dev/null

However, simpler still:

# delete needed files
find /Users/*/Library/Preferences/ -maxdepth 1 -name "com.smarttech*" -exec rm -f {} ;
find /Users/*/Library/Application Support/ -maxdepth 1 -name "Smart Technologies*" -exec rm -rf {} ;