Mac OS - Action Script fails

(imported topic written by ken@gracenote91)

Trying to write a fairly simple task… but the action script always fails.

On the command line on my Mac I can successfully do the following:

sudo /Library/AgentService/bin/uninstall

So I figure, hey, this is gonna be easy. Just create a task and have the action script be:

wait /Library/AgentService/bin/uninstall

So I reinstall the application on my mac, wait till it shows up in TEM Console. Using finder I visually confirm that this file exists: (Macintosh HD/Library/AgentService/bin/uninstall)

I run the task agains the mac and it fails. I visually confirm that the application is still installed.

I’ve tried it a number of other ways as well, including:

wait “sudo /Library/AgentService/bin/uninstall”

wait /bin/sh -c “/Library/AgentService/bin/uninstall”

wait “/Library/AgentService/bin/uninstall”

…and all, as expected, fail.

Advice?

(imported comment written by SystemAdmin)

Hello Ken. Take a look at the following post:

https://www.ibm.com/developerworks/forums/thread.jspa?messageID=14755352&#14755352

It suggests the following should work:

wait /bin/sh -c “/Library/AgentService/bin/uninstall”

or

wait /bin/bash -c “command”

Can you share the client log file where it fails?

You might also put the following in the actionscript:

continue if {exists file “Library/AgentService/bin/uninstall”}

(this will tell you if TEM sees the file)

You might also try something like:

wait /bin/sh -x “command” > /some/log/file

This might capture more info from sh.

(imported comment written by SystemAdmin)

Ken:

Well, from what I hear, you may have already gotten this to work, but for others, I thought I’d post some suggestions, when working on a situation like this (this is what I was going to post), before I heard that your problem was solved:

So, as you know OSX commandline adminisration is a ‘strange beast’; half BSD, half GUI,

etc. and the GUI often ‘hides’ things from you. So, scripting tasks sometimes work

in non-intuitive ways, especially as the Agent runs as root ( so you shouldn’t have

to sudo), but the Agent doesn’t have the same commandline context that you have from

Terminal.app. Some things may work from your commandline, but not in a script, and vice-versa.

Now, another weird thing that I’ve experienced, is that some vendors work very hard to make it

difficult to script their uninstalls

System utilities are notorious for this

.

To test your problem on a simple scale, I downloaded & installed a utility called Remote Desktop Connection

(actually an OSX version of MSTSC, from Windows) on my OSX10.6.7 box, and then used the following

Actionscript in a fixlet, to remove it:

continue if {exists folder “Remote Desktop Connection.app” of folder “/Applications”}

wait sh -c “rm -rf ‘/Applications/Remote Desktop Connection.app’”

[Looking elsewhere in the forum, this appears to be the desired way to remove an OSX application that

doesn’t provide an uninstall-script (this is essentially the same thing that’s done when

you move an application to the Trash icon). Another reason for doing it this way, is that

it bypasses a lot of the controls that the OSX GUI has].

Now, I often change my fixlet ‘success-criteria’ to ‘all lines have run’ or

specifically enter something like I did for the above, which was:

exists folder whose (name of it as lowercase contains “remote desktop”) of folder “/Applications”

.

Another thing to be aware of, on OSX/UNIX, is that it’s difficult to delete a file

or directory that a service is actively using. If this backup utility is

actively running and using these files while you’re trying to remove them,

it may not let you. Additionally, OSX may even ‘lie’ and tell you it’s deleted them when

it actually hasn’t. So if the above doesn’t work, you might try checking to make sure that

the service has actually been stopped, or shutting it down with a prior actionscript line. You might have

success with something like:

/sbin/service iqbackupsvc stop

or

launchctl unload /System/Library/LaunchDaemons/org.iq.backup.xml

Finally, scripted TEM tasks on OSX/UNIX are often easier to write and debug by creating a .sh script that

successfully runs from the commandline and is then substituted into a fixlet. so if I had a script containing

command a

command b

that successfully ran from the command prompt, I might put it in a fixlet as:

appendfile #!/bin/sh

appendfile command a

appendfile command b

move __appendfile runme.sh

wait chmod a+x runme.sh

wait /bin/sh -c “runme.sh 2>&1 /tmp/blahstatus”

(or I could just run it as 'wait runme.sh) But notice that the status passed back from the ‘runme.sh’ line, here, may not indicate the success or failure of “command b”.

It may just indicate that the shell was successfully started and some command was run. The command,

itself, may or may not correctly pass status back to the initiating script (in this case, the actionscript).

That said, it’s often wise to handle status-checking in your script and to output the status code with

something like …2>&1 file.txt. Or, you can then check this returncode by looking in the TEM log on the OSX endpoint

(remember that this is usually /Library/Application Support/BigFix/BES Agent/__BESData/__Global/Logs with the log file named after the current date, suffixed with .log).

So, hopefully, one or some of these suggestions might help the next person.

all best,

jpsthecelt

1 Like

(imported comment written by ken@gracenote91)

A follow up to this…

I am having failing on a substitution in the action script:

// Continue with modified BigFix generated code

Failed

if {not active of action OR (exists file whose (name of it ends with “.mpkg” OR name of it ends with “.pkg”) of it) of folder ("/Users/" & {name of current user} & “/Downloads/” & “BESMNTPT2330656345275824”)}

How would I properly format this?

Origionally, the Mac OS Software deployment wizard put everything in /tmp/ but for reasons associate with the vendor in question, I am trying to move everything from /tmp/ to the current user’s download directory

Thoughts?

Ken