Run Jamf CLI commands inside a bash script

BusterCasey
New Contributor II

Hello folks,

 

any chance to run Jamf CLI commands like "sudo jamf policy" or "sudo jamf launchSelfService" from a bash script?

 

Thanks a lot|

1 ACCEPTED SOLUTION

PaulHazelden
Valued Contributor

Try using the fullpath for jamf

/usr/local/bin/jamf
I have found some scripts fail until I use the full path to the command.

View solution in original post

6 REPLIES 6

sdagley
Esteemed Contributor II

@BusterCasey Run your script via sudo (e.g. sudo ./myscript.sh) and in the script don't prefix the jamf binary cals with a sudo (i.e. use 'jamf policy' instead of 'sudo jamf policy')

BusterCasey
New Contributor II

Thank you, It works. I realized that the issue is that i launch the bash script from a Applescript:

do shell script "/path/to/yourscript.sh" with administrator privileges

Every bash commands inside the sh works great (sudo or not) except the jamf cals to the jamf binary. Can't understand why 😥

PaulHazelden
Valued Contributor

Try using the fullpath for jamf

/usr/local/bin/jamf
I have found some scripts fail until I use the full path to the command.

dhausman
Contributor

I Set a policy up in self service to be able to run what I call a check in.

 

 

#!/bin/bash
sudo jamf policy; sudo jamf recon

 

 

 

Even gave it an icon.  That way I can scope something out and tell a user to go to self service and check in so we don't have to wait..

Screen Shot 2022-03-28 at 11.18.43 AM.pngScreen Shot 2022-03-28 at 11.19.29 AM.png

BoscoATX
New Contributor III

User the full path: /usr/local/bin/jamf

I have to do this with commands in Apple Remote Desktop

The easy way to find the full path for any command is to use the which command in terminal,
so 
which jamf
Returns
/usr/local/bin/jamf