Bash Script

Raj_Jenkin
New Contributor III

Dear All,

I would like to create an executable bash script for the scripts below:

sudo sh -c 'echo "Sandboxing Relaxed" >> /etc/cups/cups-files.conf'
sudo launchctl stop org.cups.cupsd

Can anyone help?

4 REPLIES 4

PaulHazelden
Contributor III

I use xcode to create my Bash scripts. When you make a new script file it will put the right format in there to start with. All Scripts start with

#!/bin/sh

As the very first line.
Then it gets your script bit inserted on the lines following that.
You are on a Mac and want the # symbol, its Alt + 3.
Save the file. It needs to be executable, so it needs permissions to do this. For that I use the chmod command in Terminal.

chmod -Rf 777 /Path/to/File.sh

That will make the file executable by everyone and readable by everyone and writable by everyone.
The numbers are for Owner, Group, Others
Read = 4
Write = 2
Execute = 1
Add up what you want in the 3 numbers and put it in.

755
Read and write and execute for the Owner 4+2+1=7
Read and execute for the Group 4+1=5
Read and execute for Others 4+1=5
There are other ways to achieve this. This is just the way I do it.

If you run the script from Jamf, you shouldn't need the sudo, as the script will be running as the root superuser.

Your script will be along these lines...

#!/bin/sh

sh -c 'echo "Sandboxing Relaxed" >> /etc/cups/cups-files.conf'
launchctl stop org.cups.cupsd

Raj_Jenkin
New Contributor III

Hi Paul,

Thanks for the quick response.

I have pasted this bash script in Automator to test. However, I'm still getting permission errors. Please see the attached screenshot.

!/bin/sh

d4fc37c2b38349f2b8691ffc1e009c15

sh -c 'echo "Sandboxing Relaxed" >> /etc/cups/cups-files.conf'
launchctl stop org.cups.cupsd

PaulHazelden
Contributor III

Running the script locally like that will give a permission error. It needs to be run as root without the sudo.
Try in Jamf > Computers > Management Settings > Computer Management > Scripts
Make a new script and paste the script in there. Then use Jamf to push it out to the device. If it is a quick test you can use JAMF Remote to find the test Mac and the script you just saved and run it.
This should not get the errors, because it is run as root by the JAMF system.

Raj_Jenkin
New Contributor III

Hi Paul,

All good! Thanks for your help.