Write a script they! Run several policy id #s?

mccallister
Contributor

I need to create a script, but I haven't the faintest idea about creating scripts. I am inept at programming.

What I need is a script that will run these policy id #s in sequence

jamf policy -id 173
jamf policy -id 174
jamf policy -id 171
jamf policy -id 172

Can anyone help me with this animal?

2 REPLIES 2

mm2270
Legendary Contributor III

Hi @mccallister! Interestingly enough, what you posted is basically almost all there! :)

All you would need to do, in a very simplistic fashion, is put a shebang at the top of what you have. For example:

#!/bin/sh

jamf policy -id 173
jamf policy -id 174
jamf policy -id 171
jamf policy -id 172

That first line #!/bin/sh is what tells it to be a script, so to speak. A "shell" script specifically.

Take the above and copy/paste into a plain text file. The "plain" part is important. Shell scripts do NOT like any special formatting or odd carriage returns, etc. Best to use something like the free TextWrangler or some other plain text file editor. Try to avoid TextEdit. Despite its name, it's more of a rich text editor and likes to auto format things like those regular dashes into em dashes, which fouls up the script.

Even better would be to create the script directly in your JSS and bypass a file, unless you need to test it locally first. The JSS won't try to add in any crazy formatting to the script.

As you begin to explore scripting, you can add in more to your scripts. Like echo commands to indicate which policy is being run by the script and other stuff. But the above will get you what you need as a start.
Just make sure none of those policies are doing something like rebooting the Mac since it would interrupt the flow of the script and not allow all of them to run.

mccallister
Contributor

Thank you! I created the script directly in JSS and it works exactly like I wanted.