« network activity log | Main | netstat launch at system startup (continued) »

netstat launch at system startup

i found a way to start netstat at system startup time. after some google searches to see what is executed at system startup, it found some very useful information on www.kernelthread.com, entitled "Mac OS X System Startup". there i read about /System/Library/StartupItems and /Library/StartupItems, which contains items to be executed at system startup.

after all, now that i have set up everything, i have to say that maybe i would have better done this in /Library, instead of /System/Library.

so here are some excerpts of my terminal to show what i did:
$ sudo mkdir /System/Library/StartupItems/NetStat
Password:
$ sudo emacs /System/Library/StartupItems/NetStat/NetStat

then i modified the file to look as follows:
#!/bin/sh

##
# Start the Network Statistics
##

. /etc/rc.common

ConsoleMessage "Starting netstat Network Statistics"
/usr/sbin/netstat -i -w 60 >> /Library/Logs/netstat.log &

having this set up analogous to, lets say, /System/Library/StartupItems/CrashReporter/CrashReporter (1), there is another file which seems to be needed:
$ sudo cp /System/Library/StartupItems/CrashReporter/StartupParameters.plist /System/Library/StartupItems/NetStat/

the presence of this file is necessary, otherwise the startupitem won't be executed, although its contents are secondary.
$ sudo emacs /System/Library/StartupItems/NetStat/StartupParameters.plist

now the correct properties to make it executable
$ sudo chmod 755 /System/Library/StartupItems/NetStat/NetStat

and leave no traces - the files with the ~ are automatically generated by emacs which creates a backup every time you open a file.
$ sudo rm -f /System/Library/StartupItems/CrashReporter/CrashReporter~
$ sudo rm -f /System/Library/StartupItems/NetStat/StartupParameters.plist~

now netstat is launched at startup, you can check it in system.log, look for a message "ConsoleMessage: Starting netstat Network Statistics".
combined with the log file treatment i introduced yesterday, this makes a useful tool for your network statistics.

(1) while you're at it, you may want to disable the annoying crashreporter - just comment out with hash key # the line which says /usr/libexec/crashreporterd and it will not launch at startup any more.

update: see also the information given some days later.

Post a comment