Skip to main content
Question

Problems with Script run from a policy


Forum|alt.badge.img+3

Hello, we have a situation where we want to stop and start smb on a 10.13.6 server each night. I created a policy to run the script on a daily basis. The script is very simple:

!/bin/bash

serveradmin stop smb
sleep 10
serveradmin start smb

When the script is run via JAMF Remote it runs fine but when it runs via the policy I get the error posted below. Any help would be greatly appreciated.

easyedc
Forum|alt.badge.img+16
  • Esteemed Contributor
  • February 13, 2019

So first, did you copy your script into this? If so, it's missing it's shebang

#!/bin/sh

Secondly, the error it's replying with indicates the problem in that it can't actually find any binary "serveradmin" so I would go to the target and run a

$ which serveradmin

and confirm it's actually got that as a binary.


easyedc
Forum|alt.badge.img+16
  • Esteemed Contributor
  • February 13, 2019

.... Or is serveradmin your user? That would make more sense. JAMF policies run as root, that could be your problem.

[more coffee needed this morning]


thebrucecarter
Forum|alt.badge.img+14

Forum formatting ate the pound sign on the shebang line.

Possibly you need the full path to serveradmin?


Forum|alt.badge.img+18
  • Contributor
  • February 13, 2019

@jrweber2016 See if this makes a difference.

#!/bin/bash

/Applications/Server.app/Contents/ServerRoot/usr/sbin/serveradmin stop smb
sleep 10
/Applications/Server.app/Contents/ServerRoot/usr/sbin/serveradmin start smb

exit 0

mm2270
Forum|alt.badge.img+16
  • Legendary Contributor
  • February 13, 2019

Like @ryan.ball suggested, try using the full path to serveradmin. The most likely problem is that when the policy runs at check-in, it's being called by the Jamf LaunchDaemon and sometimes launchd jobs don't have the same PATH environment settings that the Terminal might have. When it runs, it probably doesn't know how to resolve serveradmin into the full path to the binary, which it of course needs to be able to do to use it at all.

General rule of thumb when writing scripts is that, unless it's something very commonly used in bash, it's best to put in the full path to executables and commands, just to cover yourself.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings