Script exit code: 127

JDaher
New Contributor III

Caveat emptor: I'm new to Jamf and this is my first post here.

I created a very simple script to change the computer name. I uploaded the script to Jamf Pro and created a policy to deploy the script. It works but Jamf reports it as a failure with this error:

**Script exit code: 127

Script result: /Library/Application Support/JAMF/tmp/JD - TEST: Change Computer Name: line 10: end: command not found

Error running script: return code was 127**

There is nothing in my script that references /Library/Application Support/JAMF/tmp

Can somebody tell me what I'm missing?

Thank you so much

6 REPLIES 6

Tribruin
Valued Contributor II

Can you post your script? If you have any company/personal information just sanitize it. It is probably an error in your script. (Hint: If you click on the button >_ and paste your code between the tick marks, it will properly format your code and make it easier to read)

JDaher
New Contributor III
#!/bin/bash

#This script will change the computer name. 

sudo scutil --set HostName <ComputerName>
sudo scutil --set ComputerName <ComputerName>
sudo scutil --set LocalHostName <ComputerName>

end

Tribruin
Valued Contributor II

Take the end command out. The script will end by itself. (You can also use exit, but it redundant).

ETA: The sudo commands are redundant and not necessary if you are running this in a Jamf policy. All scripts run as root when run from Jamf.

cbrewer
Valued Contributor II

What are you trying to change the computer name to? Typically you would provide computer name as a variable by either specifying it or prompting the user for it. Then your commands would look something like scutil --set LocalHostName ${computerName}. Also, no need to put sudo in scripts run by Jamf since they are already running as root.

Example:

#!/bin/bash

#This script will change the computer name. 

computerName="1234567890"

scutil --set HostName ${computerName}
scutil --set ComputerName ${computerName}
scutil --set LocalHostName ${computerName}

Example2:

#!/bin/bash

#This script will change the computer name. 

computerName=$(/usr/bin/osascript<<END
tell application "System Events"
activate
set the answer to text returned of (display dialog "Enter new computer name" with title "Computer Name Change" default answer "$(scutil --get ComputerName)")
end tell
END)

scutil --set HostName ${computerName}
scutil --set ComputerName ${computerName}
scutil --set LocalHostName ${computerName}

JDaher
New Contributor III

Wow! One little word made all the difference. I took the end and sudo commands out and it worked without any errors. I was also getting the same error in another script that didn't even have the sudo command, but it did have the end command. I took that out and now that scripts executes with no errors as well.

@cbrewer: not only am I new to Jamf but I'm just learning to script, so still learning how to use variables. The goal here is to set the computer name to comply with the company's naming convention without user intervention (they don't know the naming convention anyway). I know my current solution is cumbersome but it's a start. I was thinking I could refine it by doing what you suggested and then using the Parameter Label fields in the options section of Scripts in Jamf (?). They would have to be defined every time I need to change the name on a machine, and consequently could only be scoped one machine at a time... Fortunately this isn't a big problem and I'd have to use it only every now and then.

Anyway, thank you so much to both of you. I really appreciate you taking the time to help a newbie out. I'm sure I'll be coming back here frequently.

Tribruin
Valued Contributor II

Glad to help. Just remember the goal of scripting is to make your job as an Admin easier. What @cbrewer provide is a good start to think about setting your computer names. I would suggest the next step would be to decide how can you automate the creation/generation of your computer name. Is the name something that be calculated programmatically or is information t from IT or the user.

We all started from scratch at some point. There are a lot of good materials on the web to help. Google is great help if you just want to ask "How do I do XXXX in bash". Since you are a Jamf customer, check out the online Jamf training catalog. They have a bunch of videos, broken in to two series (Scripting & Advanced Scripting). These would be a good place to start.

Also, I highly recommend a blog by Armin Briegel. He has made a number of presentations on scripting in bash & zsh. Checkout his blog at ScriptingOSX.

And if you run in to challenges, feel free to ask questions here.

Good luck.