Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Set system and network prefs from the Terminal UNIX
Apple has included two very useful command line utilities, networksetup and systemsetup, as part of Mac OS X Server for some time now (since 10.2?). These are utilities that provide (in most cases the only) command-line counterparts to many of the preference panes, such as Network (very thoroughly, I might add), Date & Time, Energy Saver (yes, there is also pmset), Startup Disk, and some of Sharing.

I have discovered that these two utilities are now included with the freely-available Apple Remote Desktop Client, and they are perfectly willing to run in Mac OS X Client (not just Mac OS X Server). Since they are now freely available, I can recommend these to all the admins and shell scripters in the house. These tools make use of the appropriate frameworks / APIs, and absolutely represent the Apple-sanctioned way of getting the job done. As mentioned, these tools have been in production use in OS X Server for a while, and I have used them a bunch and never had any problems.

Install Remote Desktop via the link above (if you don't have it already; check your Sharing prefs panel), and have a look in /System -> Library -> CoreServices -> RemoteManagement -> ARDAgent.app -> Contents -> Support. Now type sudo ./networksetup -help and sudo ./systemsetup -help for the full scoop on everything these two programs can do.

Read the rest of the hint for a little more detail on these programs, as well as a warning about trying to get them to run on 10.2.

[robg adds: These really are very powerful programs, as you'll see if you read the help screens. I made a symbolic link to these files from my user's bin folder, so that they're on my path and are easily run (though you'll want to do so with sudo).]

Running otool -L to see what frameworks networksetup uses reveals a bunch of Apple's private frameworks, in addition to the public SystemConfiguration framework that does most of the work here (lines wrapped for narrower display):
root@pimp $ otool -L networksetup
networksetup:
  /System/Library/PrivateFrameworks/Admin.framework/Versions/A/Admin
     (compatibility version 1.0.0, current version 1.0.0)
  /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation
     (compatibility version 300.0.0, current version 500.0.0)
  /System/Library/Frameworks/SystemConfiguration.framework/Versions/
     A/SystemConfiguration (compatibility version 1.0.0,
     current version 84.0.0)
  /System/Library/PrivateFrameworks/Apple80211.framework/Versions/
     A/Apple80211 (compatibility version 1.0.0, current version 2.0.0)
  /System/Library/PrivateFrameworks/NetworkConfig.framework/Versions/
     A/NetworkConfig (compatibility version 1.0.0, current version 1.0.0)
  /System/Library/Frameworks/SecurityFoundation.framework/Versions/
     A/SecurityFoundation (compatibility version 1.0.0, current version 6.0.0)
  /usr/lib/libSystem.B.dylib
     (compatibility version 1.0.0, current version 71.0.0)
Note of potential doom: Read this entire paragraph before doing anything mentioned herein. I almost posted a hint about halfway through 10.2 about how to get these utilities to work in 10.2. Turns out that the 10.2 versions of the utils would simply check for the existence of /System -> Library -> CoreServices -> ServerVersion.plist, and if it wasn't there, it would bail assuming that it was not being run on server (this was deduced by running strings(1) on the systemsetup program itself).

I found that by simply touching ServerVersion.plist, the utility would not only run, but work perfectly. I just had to make sure to delete ServerVersion.plist when I was done, otherwise other things like installers and preference panes would think I was running server also, and behave differently. However, given that the utilities were not freely available, it seemed like there wasn't much point in posting about it to a Mac OS X-centric community.

Incidentally, trying the ServerVersion.plist thing nowadays will make Panther hate you long time. I'm not kidding. You will need to reinstall OS X if you try it (I tried it twice just to be sure!). As soon as that file is detected (and various things must be looking fairly frequently), you will lock, and you'll never see your desktop again until after spinning the install CDs :)
    •    
  • Currently 1.60 / 5
  You rated: 1 / 5 (5 votes cast)
 
[38,747 views]  

Set system and network prefs from the Terminal | 22 comments | Create New Account
Click here to return to the 'Set system and network prefs from the Terminal' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
GREAT! Thank you so much!
Authored by: nick on Dec 16, '04 11:36:47AM

.



[ Reply to This | # ]
Locations?
Authored by: ssevenup on Dec 16, '04 11:38:57AM

Funny, neither allows changing network locations?

---
Mark Moorcroft
ELORET Corp. - NASA/Ames RC
Sys. Admin.



[ Reply to This | # ]
Locations?
Authored by: gneagle on Dec 16, '04 12:30:01PM

scselect allows you to change Network Locations from the command line.

scselect "Home"

scselect "Automatic"



[ Reply to This | # ]
Why Symbolic Link?
Authored by: d00d on Dec 16, '04 11:44:26AM

Hey Rob, why use a symbolic link? It's far easier to make an alias and when you define that alias, make sure they are run using sudo.



[ Reply to This | # ]
Why Symbolic Link?
Authored by: extra88 on Dec 16, '04 12:30:57PM

Making a symlink in a default path location makes it more easily available for *all* accounts on the computer. Shell aliases benefit only the individual user.

I disagree that creating an alias being "far easier" than a symlink. If anything, creating the symlink is slightly easier.

The symlink is one command and one password (or no password if you've already used sudo recently) and you can use tab completion to reduce the amount of typing. To make an alias you have to navigate to the desired section of the config file then either type out the paths or use tab completion in the terminal then copy/paste. Once you've saved the change you still have to "source" the configuration file for the alias to take effect.



[ Reply to This | # ]
Both Panther and Jaguar versions
Authored by: n8gray on Dec 16, '04 03:22:31PM
I've got the following files in /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/:

ARDForcedViewer.app/         build_hd_index*        sysinfocachegen*
ARDHelper*                   networksetup-jaguar*   systemsetup-jaguar*
Remote Desktop Message.app/  networksetup-panther*  systemsetup-panther*

So make sure to make the proper symlink for your version of OS X.

[ Reply to This | # ]

Set system and network prefs from the Terminal
Authored by: hagbard on Dec 16, '04 03:50:19PM
Hi ! maybe this is because of the 10.3.7 update, but I don't have these files at all. (And ARD is installed). here's what I have :

$ ls -l "/System/Library/CoreServices/ARD Agent.app/Contents/Support"
total 32
-rwxr-xr-x  1 root  wheel  14248 16 Dec 09:48 ARD Helper
$
and 'ps ax|grep ARD' shows :

  346  ??  Ss     0:01.54 /System/Library/CoreServices/ARD Agent.app/Contents/Support/ARD Helper
  432  ??  S      0:00.34 /System/Library/CoreServices/ARD Agent.app/Contents/MacOS/ARD Agent -psn_0_1179649
am I the only one ??

[ Reply to This | # ]
Set system and network prefs from the Terminal
Authored by: dreness on Dec 16, '04 05:15:25PM

That is not the right directory, which probably means you have the older version of ARD installed. Run the installer linked in the article and you should be good to go.



[ Reply to This | # ]
Set system and network prefs from the Terminal
Authored by: deviantintegral on Dec 16, '04 07:47:59PM

From the help message:
Usage: systemsetup -getrestartfreeze
Display whether restart on freeze is on or off.

Usage: systemsetup -setrestartfreeze <on off>
Set restart on freeze to either <on> or <off>.

Does this mean that I can set my laptop to automatically reboot if it freezes? Or is this an Xserve option?

--Andrew



[ Reply to This | # ]
Set system and network prefs from the Terminal
Authored by: dfbills on Dec 16, '04 11:42:49PM

very interesting- what constitutes a "Freeze?"

---
-d



[ Reply to This | # ]
Set system and network prefs from the Terminal
Authored by: n8gray on Dec 17, '04 04:49:37PM
very interesting- what constitutes a "Freeze?"

In my experience, running VISE installer usually constitutes a freeze before too long...

;^)

[ Reply to This | # ]

Set system and network prefs from the Terminal
Authored by: dreness on Dec 17, '04 05:48:26PM
This is positioned as a server feature, which is why the option is absent from client's Energy Saver preference pane. It is present in pmset, however...
sudo pmset -a autorestart 1
would enable it on an os x server machine.

I think the problem you'll have on client is that a key piece is missing: watchdog. In OS X Server, watchdog's job is to watch a list of key processes and restart them if they die; watchdog also has the ability to reset a timer in the power management unit (PMU). When auto-restart is enabled on a server, this timer is activated and set to 5 minutes. The watchdog process periodically resets the timer. When the timer hits zero, the PMU assumes that wathdog (and most likely the rest of the system) is stuck, and triggers a hard reset.

You can check to see if your hardware supports auto restart by searching in the IO registery (but again, without os x server, I believe it is a moot point).

do a
ioreg -c IOPMrootDomain | grep Features
and then hit command F in the terminal and search for FileServer. Some of the output from my powerbook is shown below. If FileServer = Yes, then your mac should support auto restart.
andre@gyro[~]ioreg -c IOPMrootDomain | grep Features
    | | |   "Supported Features" = {"FileServer"=Yes,"ServerID"=Yes,"WakeOnACchange"=Yes$


[ Reply to This | # ]
Set system and network prefs from the Terminal
Authored by: dreness on Dec 17, '04 05:51:25PM

editor's note: the last bit was written initially with just ioreg -l; in the provided example you probably won't have to do a find for FileServer using terminal's find ;)



[ Reply to This | # ]
Set system and network prefs from the Terminal
Authored by: lunarobverse on Dec 17, '04 12:30:06AM
In
/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/
I show:
[Gibson:ARDAgent.app/Contents/Support] bamoon% ls -al
total 2000
drwxr-xr-x  11 root  wheel     374 16 Dec 21:22 .
drwxr-xr-x   8 root  wheel     272 30 Sep 16:23 ..
drwxr-xr-x   3 root  wheel     102 30 Sep 16:23 ARDForcedViewer.app
-rwxr-xr-x   1 root  wheel   26776 16 Dec 21:22 ARDHelper
drwxr-xr-x   3 root  wheel     102 30 Sep 16:23 Remote Desktop Message.app
-rwxr-xr-x   1 root  wheel  132116 16 Dec 21:22 build_hd_index
-rwxr-xr-x   1 root  wheel   86500 16 Dec 21:22 networksetup-jaguar
-rwxr-xr-x   1 root  wheel  111440 16 Dec 21:22 networksetup-panther
-rwxr-xr-x   1 root  wheel  407468 16 Dec 21:21 sysinfocachegen
-rwxr-xr-x   1 root  wheel  114524 16 Dec 21:22 systemsetup-jaguar
-rwxr-xr-x   1 root  wheel  130796 16 Dec 21:22 systemsetup-panther
So I'm assuming I can delete the versions of networksetup and systemsetup for Jaguar (10.2) and just use the versions for Panther (10.3) since I'm running 10.3.6? Would it hurt things if I deleted the Jaguar versions and rename the others to remove the "-panther"? Anyone? Anyone? Bueller?

[ Reply to This | # ]
Set system and network prefs from the Terminal
Authored by: Dephex Twin on Dec 17, '04 09:42:47AM

Why not just leave everything the way it is, and just name the symlinks whatever you want? That way there is no worry about messing anything up that ARD might count on to be there by changing names or deleting things. (Surely you don't feel the need to delete the Jaguar versions anyway in order to free up the ~150k! Right? :)

---
"Alcohol: the cause of-- and solution to-- all of life's problems."
--- Homer Simpson



[ Reply to This | # ]
Set system and network prefs from the Terminal
Authored by: lunarobverse on Dec 17, '04 11:19:11AM

Yeah, I thought about that. Guess that's what I'll be doing.

Mostly I was worried about using the wrong one and screwing something up.



[ Reply to This | # ]
Set system and network prefs from the Terminal
Authored by: bjast on Dec 17, '04 10:09:34AM

I was able to get the help portion working:

Ready: sudo ./systemsetup -help | more

systemsetup Help Information
-------------------------------------
Usage: systemsetup -getdate
Display current date.

Usage: systemsetup -setdate <mm:dd:yy>
Set current date to <mm:dd:yy>.

Usage: systemsetup -gettime
Display current time.

___________________________________________________________

But have been unable to get any of the functions to work:

Ready: otool -L networksetup
su: otool: Command not found.

I am running as root.

Hm

bjast



[ Reply to This | # ]
Set system and network prefs from the Terminal
Authored by: dreness on Dec 17, '04 05:25:44PM

otool is not related to either systemsetup or networksetup. It is a developer tool that allows, among other things, for examining which libraries / frameworks are used by a given executable. In this context, it's just here to show that these tools do their job using the same system facilities as the GUI tools.



[ Reply to This | # ]
Set system and network prefs from the Terminal
Authored by: dreness on Dec 23, '04 03:42:53AM

It's been brought to my attention that using these tools in this way without owning Apple Remote Desktop is a violation of the license. Be advised.



[ Reply to This | # ]
ARD webcast at macenterprise.org
Authored by: victory on Jan 26, '05 06:59:35PM
While I'm sure most Mac administrators are already familiar with this site, I thought I'd mention what a great resource macenterprise.org is.

For example, some of the info covered in dreness' hint is also outlined in this webcast about ARD, presented by Apple engineers/consultants. Besides containing a lot of useful info, the webcast itself was surprisingly entertaining.

[ Reply to This | # ]

Set system and network prefs from the Terminal
Authored by: uurf on Jan 29, '06 08:36:52PM

Surprisingly, among the many things you can control through these two utilities, the one you cannot turn on or off remotely is "Remote Desktop Sharing"!

Anyone know how to turn on the Remote Desktop Client via the command line?

Thanks



[ Reply to This | # ]
Set system and network prefs from the Terminal
Authored by: uurf on Jan 29, '06 09:08:29PM

This KB Doc describes how to use kickstart, which does exactly what I was looking for:

http://docs.info.apple.com/article.html?artnum=108030

"Apple Remote Desktop 2 includes the "kickstart" command line utility. It allows you to install, uninstall, activate, configure, and restart components of Apple Remote Desktop without restarting the computer. You can configure all the features found in Apple Remote Desktop preferences.

The kickstart utility is located here:
/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart"



[ Reply to This | # ]