Posted on 11-30-2023 04:31 AM
I'm looking to make a set of options available to users via 2 policies in the Self Service app.
1 policy should allow the user to set a static IP address to the interface - I've written a script that inserts dummy values for now - this script runs successfully and alters the network settings as expected:
#!/bin/bash
# sets test IP settings for Ethernet
networksetup -setmanual Ethernet 10.10.10.10 255.0.0.0 127.0.0.0
The other policy should set the network settings back to DHCP for that interface - I wrote a script for this, which does not work:
#!/bin/bash
# Set network settings back to DHCP
networksetup -setdhcp Ethernet
This DHCP script reports as having run successfully (exit code 0) but the network settings on the device haven't changed.
If I run the single line with the networksetup command locally, in Terminal, it completes and changes the network settings as expected.
If I push the script out with a policy (as opposed to making it available in Self Service) it completes and changes the network settings as expected.
Any suggestions for troubleshooting / fixing this?
I've tried:
- using "ipconfig set en0 dhcp" instead - this hasn't worked
- giving networksetup the clientID parameter as suggested here - which didn't work: Solved: Automate Setting DHCP client ID to Hostname on Mac... - Jamf Nation Community - 172304
- running the script through ShellCheck - no errors found
I haven't yet tried:
- this suggestion, since I don't understand how to "Editing the policy in the JSS console then saving with no changes": Anyone else seeing Self Service policies with only... - Jamf Nation Community - 264005
Any help appreciated
A
12-01-2023 06:11 AM - edited 12-01-2023 06:16 AM
One golden rule to remeber when comparing terminal commands to self Service is Selft Service will always run as the root admin. Some terminal commands need to be run as the current logged in user. If this is the case you will have to force your self service script to run as the logged in user and not root admin.
Here is an example script on how to run as current user not root.
#!/bin/bash
#variable for storing the current users name
currentuser=`stat -f "%Su" /dev/console`
#substituting as user stored in variable to modify plist
su "$currentuser" -c "<command to run>"
Posted on 12-05-2023 02:37 AM
Geoff,
Thanks for that - I'll give that a go, though the first networksetup command runs as the admin user just fine, so I'm not sure that the second networksetup command to set it back to DCHP should need to be run as the logged in user.