Posted on 09-26-2016 07:01 AM
I’m having some problems running a script file. I have two scripts – one works, one doesn’t. The one that doesn’t work was created by pulling lines out of the first script and modifying them to install a different program.
The script install_latest_flash_player.sh reaches out to Adobe’s website to find the URL to the latest version of Flash Player, then downloads it and installs it. This script works fine.
The script install_latest_shockwave_recopy.sh downloads the latest Shockwave DMG and installs it. The path to the latest installer does not change for Shockwave, so I stripped out the version checking. I also removed the lines relating to checking the OS version, as I’m not concerned that any of my Macs will have an old OS on them.
When I run the script to install Shockwave, the computer returns “command not found” errors for any line that isn’t an actual command (such as setting variables). If I run all of the commands manually in terminal the process works.
Some google searching found this - http://superuser.com/questions/291361/command-not-found-when-running-a-shell-script-what-did-i-break but I don't know how to use that information to fix my script, or why the original script works when it doesn't seem to call out anything different than the script I made.
Can anyone shed some light on this?
Here are the two scripts.
install_latest_flash_player.sh:
#!/bin/sh
# This script downloads and installs the latest Flash player for compatible Macs
# Determine OS version
osvers=$(sw_vers -productVersion | awk -F. '{print $2}')
# Determine current major version of Adobe Flash for use
# with the fileURL variable
flash_major_version=`/usr/bin/curl --silent http://fpdownload2.macromedia.com/get/flashplayer/update/current/xml/version_en_mac_pl.xml | cut -d , -f 1 | awk -F" '/update version/{print $NF}'`
# Specify the complete address of the Adobe Flash Player
# disk image
fileURL="http://fpdownload.macromedia.com/get/flashplayer/current/licensing/mac/install_flash_player_"$flash_major_version"_osx_pkg.dmg"
# Specify name of downloaded disk image
flash_dmg="/tmp/flash.dmg"
if [[ ${osvers} -lt 6 ]]; then
echo "Adobe Flash Player is not available for Mac OS X 10.5.8 or below."
fi
if [[ ${osvers} -ge 6 ]]; then
# Download the latest Adobe Flash Player software disk image
/usr/bin/curl --output "$flash_dmg" "$fileURL"
# Specify a /tmp/flashplayer.XXXX mountpoint for the disk image
TMPMOUNT=`/usr/bin/mktemp -d /tmp/flashplayer.XXXX`
# Mount the latest Flash Player disk image to /tmp/flashplayer.XXXX mountpoint
hdiutil attach "$flash_dmg" -mountpoint "$TMPMOUNT" -nobrowse -noverify -noautoopen
# Install Adobe Flash Player from the installer package stored inside the disk image
/usr/sbin/installer -dumplog -verbose -pkg "$(/usr/bin/find $TMPMOUNT -maxdepth 1 ( -iname *.pkg -o -iname *.mpkg ))" -target "/"
# Clean-up
# Unmount the Flash Player disk image from /tmp/flashplayer.XXXX
/usr/bin/hdiutil detach "$TMPMOUNT"
# Remove the /tmp/flashplayer.XXXX mountpoint
/bin/rm -rf "$TMPMOUNT"
# Remove the downloaded disk image
/bin/rm -rf "$flash_dmg"
fi
exit 0
install_latest_shockwave_recopy.sh:
#!/bin/sh
# This script downloads and installs the latest Flash player for compatible Macs
# Specify the complete address of the Adobe Flash Player
# disk image
fileURL="http://fpdownload.macromedia.com/get/shockwave/default/english/macosx/latest/Shockwave_Installer_Full_64bit.dmg"
# Specify name of downloaded disk image
flash_dmg="/tmp/shockwave.dmg"
# Download the latest Adobe Flash Player software disk image
/usr/bin/curl --output "$flash_dmg" "$fileURL"
# Specify a /tmp/shockwave.XXXX mountpoint for the disk image
TMPMOUNT=`/usr/bin/mktemp -d /tmp/shockwave.XXXX`
# Mount the latest Shockwave disk image to /tmp/shockwave.XXXX mountpoint
hdiutil attach "$flash_dmg" -mountpoint "$TMPMOUNT" -nobrowse -noverify -noautoopen
# Install Adobe Shockwave from the installer package stored inside the disk image
/usr/sbin/installer -dumplog -verbose -pkg "$(/usr/bin/find $TMPMOUNT -maxdepth 1 ( -iname *.pkg -o -iname *.mpkg ))" -target "/"
# Clean-up
# Unmount the Flash Player disk image from /tmp/shockwave.XXXX
/usr/bin/hdiutil detach "$TMPMOUNT"
# Remove the /tmp/shockwave.XXXX mountpoint
/bin/rm -rf "$TMPMOUNT"
# Remove the downloaded disk image
/bin/rm -rf "$flash_dmg"
fi
exit 0
Posted on 09-26-2016 07:15 AM
@nadams You have a syntax error. You removed the if statements from the original but didn't remove the closing "fi" above exit 0.
Get rid of that and it should work. Worked for me when I just tested.
Posted on 09-26-2016 07:23 AM
@chriscollins Thanks for the response. Keep in mind that I'm not very well versed in *nix commands, and am learning as I go.
Here's the result when I try running the .sh:
nadams-air:downloads nadams$ sudo sh ./install_latest_shockwave_recopy.sh
: command not foundockwave_recopy.sh: line 2:
: command not foundockwave_recopy.sh: line 4:
: command not foundockwave_recopy.sh: line 7:
: command not foundockwave_recopy.sh: line 9:
: command not foundockwave_recopy.sh: line 11:
: command not foundockwave_recopy.sh: line 13:
: command not foundockwave_recopy.sh: line 14:
: command not foundockwave_recopy.sh: line 16:
curl: (3) Illegal characters found in URL
: command not foundockwave_recopy.sh: line 18:
: command not foundockwave_recopy.sh: line 20:
: command not foundockwave_recopy.sh: line 22:
: command not foundockwave_recopy.sh: line 24:
hdiutil: attach: unknown option "-noautoopen
"
Usage: hdiutil attach [options] <image>
hdiutil attach -help
: command not foundockwave_recopy.sh: line 26:
: command not foundockwave_recopy.sh: line 28:
find: /tmp/shockwave.NTnM
: No such file or directory
Sep 26 10:17:53 installer[3900] <Critical>: PFPackage::packageWithURL - can't instantiate package: /Users/nadams/Downloads
installer: Error the package path specified was invalid: ''.
: command not foundockwave_recopy.sh: line 30:
: command not foundockwave_recopy.sh: line 31:
: command not foundockwave_recopy.sh: line 33:
: command not foundockwave_recopy.sh: line 35:
hdiutil: detach failed - No such file or directory
: command not foundockwave_recopy.sh: line 37:
: command not foundockwave_recopy.sh: line 39:
: command not foundockwave_recopy.sh: line 41:
: command not foundockwave_recopy.sh: line 43:
: command not foundockwave_recopy.sh: line 45:
nadams-air:downloads nadams$
Posted on 09-26-2016 07:34 AM
@nadams I think your problem in this case is how you copied the text of the script. it looks like you have a bunch of illegal characters including some carriage returns that show up like in "-noautoopen " (that is what the ' ') is in that command.
Did you copy this into a plain text editor?
This is what I would recommend you try. Copy the text of the script directly from what you posted in Jamfnation in your original thread into a plain text editor (remove the line with "fi" near the end of the script though). Textedit will do the trick, but you need to make sure its set to plain text in formatting (you shouldn't see any formatting bar in the document window):
If you do see a formatting bar, you can go to the Format menu and tell it to make it plain text. If it is already plain text it would offer you the option to make it Rich Text instead which is not what you want.
Save the script as a .sh, and run it with
sudo <your_username> sh /path/to/script.sh
Posted on 09-26-2016 07:44 AM
Or, you can just download a copy that is working for me that doesn't have any weird characters in it from here:
https://dl.dropboxusercontent.com/u/519077/install_latest_shockwave.sh?dl=1
But I still suggest you give my other instructions a try as writing and editing scripts REALLY requires you to use a plain text editor and getting into that habit helps. :)
Posted on 09-26-2016 07:55 AM
@chriscollins Thanks again for your help. I was already aware of the plain text requirement in scripting, and in fact had already copied the plain text from textedit, created a new file, pasted in plain text again and resaved. However that resaved file still had issues. When I copied from my original post above and pasted into a plain text textedit document and then saved it, it ran fine.
When is "plain text" in textedit not actually plain text?! I'm confused... but at least it's working now.
Thanks again for your time.
Posted on 09-26-2016 07:58 AM
@nadams you might want to use a program like TextWrangler to do your script editing. Things like curly quotes which TextEdit likes to use can cause your scripts to not work properly.
Posted on 09-26-2016 08:00 AM
@nadams Yeah, what @mpermann said. I never would suggest textedit for ongoing work but was just trying to suggest something you had already that you could get this taken care of with quickly :)
Posted on 09-26-2016 08:01 AM
It looks like the find command is failing "$(/usr/bin/find $TMPMOUNT -maxdepth 1 ( -iname *.pkg -o -iname *.mpkg ))"
Something like /usr/sbin/installer -dumplog -verbose -pkg "$TMPMOUNT/*.pkg" -target "/"
Posted on 09-26-2016 08:02 AM
I'd avoid using TextEdit entirely. Even when you tell it to use Plain text, it can occasionally still put some odd characters into the file that the shell will balk on.
My recommendation: TextWrangler is free from the App Store and is very suitable to writing or copying/pasting scripts and saving them as script files. As a few added bonuses, you don't need to make the resulting script executable before trying to run it (something you usually need to do with TextEdit saved script files), it has some great Find/Replace features, does nice syntax coloring to let you know if things are looking correct, and let's you run your script directly from the app without jumping out to Terminal. All good stuff, few of which TextEdit can do, or do well.
Just my 2¢
Edit: Looks like @mpermann beat me to the TextWrangler recommendation. But +1 to the recommendation. I obviously agree :)
Posted on 09-26-2016 08:09 AM
I've had TextEdit still change single and double quotes in to smart quotes when the option is definitely unchecked in preferences.
Definitely worth avoiding it.
Posted on 09-26-2016 09:43 AM
TextWrangler all the way, and the CLI tools let you run/test things in the app itself.
TextEdit is only a headache...
Posted on 09-26-2016 10:26 AM
Alright, so now I have a new set of problems. When I run the script against a test computer using Casper Remote, it fails... but looking at the log, I can't figure out why it failed. The install completes successfully:
Sending Wake On LAN command...
Opening SSH Connection to 10.1.28.54...
Authenticating...
Successfully authenticated.
Verifying Computer's Identity...
The MAC Address has been verified.
Checking Operating System Version...
Running Mac OS X 10.11.6 (15G1004)
Verifying /usr/local/jamf/bin/jamf...
/usr/local/jamf/bin/jamf is current (9.93)
Verifying /usr/sbin/jamf...
/usr/sbin/jamf does not exist.
Verifying /Library/Preferences/com.jamfsoftware.jamf.plist...
Preparing Policy...
Executing Policy 2016-09-26 at 1:11 PM | nadams | 1 Computer
Running script install_latest_shockwave_final.sh...
Script exit code: 0
Script result: % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
14 17.8M 14 2739k 0 0 2813k 0 0:00:06 --:--:-- 0:00:06 2813k
60 17.8M 60 10.8M 0 0 5610k 0 0:00:03 0:00:01 0:00:02 5607k
100 17.8M 100 17.8M 0 0 6395k 0 0:00:02 0:00:02 --:--:-- 6395k
/dev/disk1 Apple_partition_scheme
/dev/disk1s1 Apple_partition_map
/dev/disk1s2 Apple_HFS /private/tmp/shockwave.aBoA
Sep 26 13:11:40 installer[6427] : Product archive /tmp/shockwave.aBoA/Shockwave_Installer_Full.pkg trustLevel=202
Sep 26 13:11:40 installer[6427] : -[IFDInstallController(Private) _buildInstallPlanReturningError:]: location = file://localhost
Sep 26 13:11:40 installer[6427] : -[IFDInstallController(Private) _buildInstallPlanReturningError:]: file://localhost/tmp/shockwave.aBoA/Shockwave_Installer_Full.pkg#shockwave12.pkg
Sep 26 13:11:40 installer[6427] : Set authorization level to root for session
Sep 26 13:11:40 installer[6427] : Administrator authorization granted.
Sep 26 13:11:40 installer[6427] : Will use PK session
Sep 26 13:11:40 installer[6427] : Using authorization level of root for IFPKInstallElement
Sep 26 13:11:40 installer[6427] : Starting installation:
Sep 26 13:11:40 installer[6427] : Configuring volume "Macintosh HD"
Sep 26 13:11:40 installer[6427] : Preparing disk for local booted install.
Sep 26 13:11:40 installer[6427] : Free space on "Macintosh HD": 471.16 GB (471161982976 bytes).
Sep 26 13:11:40 installer[6427] : Create temporary directory "/var/folders/zz/zyxvpxvq6csfxvn_n0000000000000/T//Install.6427wXGeEg"
Sep 26 13:11:40 installer[6427] : IFPKInstallElement (1 packages)
Sep 26 13:11:40 installer[6427] : PackageKit: Enqueuing install with framework-specified quality of service (utility)
installer: Package name is Adobe Shockwave Player 12.2
installer: Upgrading at base path /
installer: Preparing for installation….....
installer: Preparing the disk….....
installer: Preparing Adobe Shockwave Player 12.2….....
installer: Waiting for other installations to complete….....
installer: Configuring the installation….....
installer:
#
installer: Moving items into place….....
installer: Validating packages….....
#Sep 26 13:11:43 installer[6427] : Running install actions
Sep 26 13:11:43 installer[6427] : Removing temporary directory "/var/folders/zz/zyxvpxvq6csfxvn_n0000000000000/T//Install.6427wXGeEg"
Sep 26 13:11:43 installer[6427] : Finalize disk "Macintosh HD"
Sep 26 13:11:43 installer[6427] : Notifying system of updated components
Sep 26 13:11:43 installer[6427] :
Sep 26 13:11:43 installer[6427] : **** Summary Information ****
Sep 26 13:11:43 installer[6427] : Operation Elapsed time
Sep 26 13:11:43 installer[6427] : -----------------------------
Sep 26 13:11:43 installer[6427] : disk 0.07 seconds
Sep 26 13:11:43 installer[6427] : script 0.00 seconds
Sep 26 13:11:43 installer[6427] : zero 0.00 seconds
Sep 26 13:11:43 installer[6427] : install 2.08 seconds
Sep 26 13:11:43 installer[6427] : -total- 2.15 seconds
Sep 26 13:11:43 installer[6427] :
installer: Running installer actions…
installer:
installer: Finishing the Installation….....
installer:
#
installer: The software was successfully installed......
installer: The upgrade was successful.
"disk1" unmounted.
"disk1" ejected.
Running Recon...
Retrieving inventory preferences from <casperserver>...
Finding extension attributes...
Locating package receipts...
Locating accounts...
Locating applications...
Searching path: /Applications
Locating hard drive information...
Locating software updates...
Locating printers...
Locating hardware information (Mac OS X 10.11.6)...
Gathering application usage information...
Submitting data to <casperserver>...
76
Submitting log to <casperserver>
Finished.
Anybody see why Casper Remote thinks this failed?
Posted on 09-26-2016 03:26 PM
@nadams What version of the JSS are you running? There reason being that the text in your output has the word "error" in it and prior to JSS 9.82 the jamf binary would still report a policy having failed if the word error ever showed up in the output regardless of the actual exit status of the script or package.
Posted on 09-27-2016 04:59 AM
@chriscollins That's pretty funny... However, my JSS is on 9.93. It looks like it only "fails" if I run it through Remote. Setting it up as an actual policy works fine.
Posted on 09-30-2016 10:17 AM
Casper log is saying it failed because of this line:
Sep 26 13:11:40 installer[6427] : -[IFDInstallController(Private) _buildInstallPlanReturningError:]: location = file://localhost
just add 2>/dev/null to the end of the installer line to redirect stderr