Problems with Script run from a policy

jrweber2016
New Contributor

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.ad4e303f5ae14c34a287de12e5787704

5 REPLIES 5

easyedc
Valued Contributor II

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
Valued Contributor II

.... 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
Contributor II

Forum formatting ate the pound sign on the shebang line.

Possibly you need the full path to serveradmin?

ryan_ball
Valued Contributor

@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
Legendary Contributor III

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.