Script Order / Priority

ryan_panning
New Contributor

This has probably been brought up before but I couldn't find anything in
the archives. Anyway, I have a policy setup to run two scripts that need
to be run in a certain order. They are named in alphabetical order.
However, there is no consistency to which order they really run. If you
edit the policy they are listed in the proper order, but if you look at
the policy "plan" the order is opposite. When I actually run the policy
on a computer they run in random order. So, what is the proper way to
get scripts to run in order?

Thanks

~ Ryan

11 REPLIES 11

Janowski
New Contributor II

just to be sure, are they both set to the same 'priority' of before, after or at reboot?
If one was set to after, it would run second, even if the name was alphabetically first, I believe.

ben janowski
Senior Macintosh Support Technician
Kohl's Mac Support Team
262.703.1396 | benjamin.janowski at kohls.com

ernstcs
Contributor III

Correct, scripts should run in alphabetical order, and follow the priority.

ryan_panning
New Contributor

Yes, both are set to Before. The names are:

getLongestUser.php
getRealName.sh

I would just combine them but as you can see, one is PHP and the other is Bash.

~ Ryan

tlarkin
Honored Contributor

What I do is that I set up scripts as manual trigger policies, so that
in a parent script it executes them in order. That way I don't have to
worry about using numbers and letters to do the alpha numeric system of
priority.

So, for example:

#!/bin/bash

tons of parent commands

jamf policy -trigger myscript1

more unix commands

jamf policy -trigger myscript2

exit 0

So I execute the script when need be, or the command. I then
consolidate scripts with Casper features. Like for example my bind
script is not needed, as the Casper client can set BIND by smart group
and auto run data.

tlarkin
Honored Contributor

Ryan, you can call different languages with in the same script...

Try this

#!/bin/bash

my shell commands

#calling php /usr/bin/php <<EOF

a bunch of php commands EOF

last unix commands

exit 0

I do this all the time with in shell for other languages. Well, not
all the time, but sometimes.

ryan_panning
New Contributor

Interesting, is there a way to pass variables between the two (in and out)? At this point I’ve been setting temp files with the data to pass back and forth. Thanks

~ Ryan

Not applicable

In, yes, out, no. But you can redirect output to a variable if you want...

tlarkin
Honored Contributor

Yes, in my post image script I call Apple Script and it uses shell
variables. Below you can see shell variables being input into a Apple
Script, also what you write in PHP can probably be translated into a
different language. I don't know a lot of PHP but if you could describe
what you want to accomplish we could maybe do it all in shell

/usr/bin/osascript <<AppleScript tell application "System Events" keystroke "$admin1_short" keystroke return delay 3.0 keystroke "$admin1_passwd" delay 3.0 keystroke tab keystroke return end tell AppleScript

It is basically calling variables for user name and password that are
hard coded in my shell script.

tlarkin
Honored Contributor

Yes input is what I meant, output can be tricky. :)

jarednichols
Honored Contributor

+1

l337 5cr!p70r

:)
--
Jared F. Nichols
Desktop Engineer, Client Services
Information Services Department
MIT Lincoln Laboratory
244 Wood Street
Lexington, Massachusetts 02420
781.981.5436

ernstcs
Contributor III

Geez Jared, don't encourage him!