How can I run the following Unix command (script?) on Macs?

0

I am in a situation where I was informed very late that a program we use to track inventory will have it's EOL October 31st. We have about 400 Mac computers where we have to uninstall the old version (not necessary but proper) and install the newest one. I am looking to use ARD for this (Apple Remote Desktop) but need to get the script working first.

Jampf isn't an option due to cost. I am not a Mac person and I'm finding out that batch files are specifically a Windows thing. Below is the script that was suggested on the forums. I have the file saved on a Network Share. I'll show the Unix command that was suggested and the one I'm trying to use with obvious substitutions.

  • Suggested: cd /Users/Shared/ ; curl -k -O https://server.hostingyourfiles.com/samanage.zip ; unzip samanage.zip ; /Users/Shared/samanage/Samanage_Agent_*.app/Contents/MacOS/installbuilder.sh --mode unattended ; rm -rf /Users/Shared/samanage/

  • Mine: cd /Users/Shared/ ; curl -k -O smb://word.word/word/word Mac/Samanage_Agent_1.1.72_1.1.37_203_30_installer ; unzip samanage.zip ; /Users/Shared/samanage/Samanage_Agent_*.app/Contents/MacOS/installbuilder.sh --mode unattended ; rm -rf /Users/Shared/samanage/

With the above, I am getting the following errors when I paste the Unix command in the terminal:

curl:(67) login denied
curl: (6) Could not resolve host: Mac
unzip: cannot find or open samanage.zip
-bash /users/shared/samanage/smanage_agent app/contents/macos/installbuilder.sh: no such file or directory

Does it have to be a URL? Is using a script even the most efficient method using ARD? Would I be able to just push the new install using ARD without a script? Should I bypass all of this and email the installer to users? Excuse my ignorance on this subject and thanks in advance for any help.

cj riveron

Posted 2017-10-27T17:08:00.240

Reputation: 1

Answers

1

There are a two major problems in your version of the script:

  • SMB generally requires authentication; the first error you get, "curl:(67) login denied" indicates that this failed in your case. Note that even if the client is already authenticated to the server and has the relevant folder mounted, curl will attempt to make its own connection to the server and download the file over that. You either need to put the file somewhere guest-accessible (an HTTP server is probably easier than SMB), or find a different way of getting it to the client.

    ARD is actually an option here; you could use its Copy Items option (under the Manage menu, or the Copy button in the toolbar) to copy the file from your admin station to the clients, and then run the install script as a separate step. Also, ARD can copy entire folder structures, so you don't have to send a .zip file and then expand it on each client; just send the expanded folder.

    BTW, there's another problem with that curl command: the filename appears to have a space, which must be quoted or escaped so that it'll be treated as a single URL with a space rather than two separate URLs.

  • The file appears to be named "Samanage_Agent_1.1.72_1.1.37_203_30_installer", but you have a command to unzip a file named "samanage.zip". Either change the name of the file you're downloading/sending to "samanage.zip", or edit the unzip command to match the actual name.

  • Another problem (which is also in the original script) is that it blindly goes through all of the steps even if one fails partway through. For example, in this case the curl command failed, so even if the filename was right there wouldn't be anything to unzip, so then trying to run the expanded file couldn't possibly have worked...

    Unless you have a more sophisticated script that can recover from errors, it's generally best to have the script exit rather than trying to continue. You can do this either by adding the command set -e at the beginning of the script, or by joining the commands with && instead of ;. The && option also lets you add an error handler with ||:

    cd /Users/Shared &&
    curl -k -O https://server.hostingyourfiles.com/samanage.zip &&
    unzip samanage.zip &&
    /Users/Shared/samanage/Samanage_Agent_*.app/Contents/MacOS/installbuilder.sh --mode unattended &&
    rm -rf /Users/Shared/samanage/ ||
    echo "Installation failed on $HOSTNAME"
    

Gordon Davisson

Posted 2017-10-27T17:08:00.240

Reputation: 28 538