Unexpected end of file error

isterling_goaaa
New Contributor III

UPDATE: This script had hidden CRs in it that I couldn't see in some of my text editors. I've re-typed it and it runs as expected. I'll see if I can post an update to the original link.

I've been trying to run this on my High Sierra mac (10.13.6) and I keep getting the following error:

sudo sh ./Symantec_DLP.sh
: command not foundline 11:
./Symantec_DLP.sh: line 19: syntax error: unexpected end of file

Any suggestions?

8 REPLIES 8

mm2270
Legendary Contributor III

What's on line 11 and 19? Without seeing the script it's kind of hard to suggest anything.

OTOH, unexpected end of file can sometimes mean a formatting issue with the script. Did you make the script, or copy/paste it from somewhere online? If you did the latter, what application did you copy it into? Some text editors, most notably TextEdit, are notorious for adding all kinds of rich text formatting into text files, which will mess up a shell script.

isterling_goaaa
New Contributor III

Oh, my apologies. I posted this in the discussions for the Symantec DLP EA script, straight from the jamf.com 3rd party download list, so I figured that would be a given.

I don't see anything glaringly wrong with this script, but it's failing every time.

I've tried the following:
1. Removing all blank lines
2. Removing unnecessary indents (last line)
3. Running the command on line 13 by itself

Only item 3 was successful.

The script, in case the link doesn't work for you:

#!/bin/sh
#
############################################################################
#
#  Created by Claudio Higuchi
#  Created on 6/17/17
#  Extension Attribute checks if Symantec DLP is installed.
#
############################################################################
#

if [ -f "/Library/Manufacturer/Endpoint Agent/Resources/info.plist" ] ; then
    VERSION=$( defaults read "/Library/Manufacturer/Endpoint Agent/Resources/info.plist" CFBundleShortVersionString )
 else
    VERSION="Not installed."
fi

 echo "<result>$VERSION</result>"

mm2270
Legendary Contributor III

Ok, I had to look that script over several times, but I'm wondering about something. Since I don't have any type of Symantec tools installed, I have no way of checking this, but, is the "Endpoint Agent" in that path just a folder? Or is it an app? If it's an app, then the .app extension is missing from the path line. Also, I noticed that Info,plist is written as info.plist (note the lowercase "i" instead of uppercase) Unless Symantec is breaking a very standardized rule of Info.plists and using a lower case info, which I doubt is the case, then I'm wondering it that needs to be changed to:

if [ -f "/Library/Manufacturer/Endpoint Agent/Resources/Info.plist" ]; then

One of those might possibly be causing the problem, but again, I really don't know since I don't have this DLP tool installed so I can't confirm anything. Might be worth checking on though.

isterling_goaaa
New Contributor III

UPDATE: I redid the script, copying & pasting into a different editor, and the new script worked. Sneaky hidden ^Ms.

Yeah, the filename is capitalized, but that's not responsible for the unexpected end of file error; if case sensitivity were the issue, it would produce a file not found error when I run just the defaults read "/Library/Manufacturer/Endpoint Agent/Resources/info.plist" CFBundleShortVersionString command by itself; this command runs just fine as it is. I'm actually thinking of just hand-typing or even rewriting this script in a *nix editor just to ensure there aren't any hidden ^M's I'm not expecting that aren't showing up in my other editors....

Thank you for taking a look at it though. :-D

sdagley
Esteemed Contributor II

@isterling.goaaa That script works fine on my Sierra Macs with DLP installed so it does sound like you've got a problem in your version. Any chance the quotes around the file path turned into smart quotes in your editor?

BTW, If you want a Mac friendly text/programming editor that will show invisible characters take a look at BBEdit. The text display options are under the View menu in the Text Display sub-menu.

isterling_goaaa
New Contributor III

I've used textwrangler, gedit, xcode, vscode, and vim. None of those have turned the quotes into smart quotes before, but it's possible there's a setting I've missed. I'll take another look though.

I tried downloading the original file again, and the same thing happened. I'm wondering if it's just High Sierra's version of /bin/sh that's being fussy? When I rewrote the script, I set it to use /bin/bash instead.

mm2270
Legendary Contributor III

Ok, so it was formatting, as I originally suspected. That's usually the main reason for the unexpected end of file errors. Those hidden Windows carriage returns will get you every time! :)

Glad you got it figured out.

markstan
New Contributor

If you're comfortable in Vi, it's well-documented how to replace CRLF with LF and global substitution (https://stackoverflow.com/questions/5939142/replacing-carriage-return-m-with-enter and similar).

If you don't want to re-type, dos2unix will convert.

# install Homebrew if it's not already there ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" brew install dos2unix dos2unix file.sh