2 # Copyright (c) 2004-2009 Apple Inc.
6 # Collect system & network configuration information.
9 PATH
=/bin
:/usr
/bin
:/sbin
:/usr
/sbin
12 if [ ${EUID} -ne 0 ]; then
16 OUT
="mobility-info-`date +'%m.%d.%Y.%H%M%S'`"
18 if [ -d ~
/Desktop
]; then
20 elif [ "`readlink /tmp`" = "private/var/tmp" ]; then
21 OUTDIR
=/Library
/Logs
/CrashReporter
/SystemConfiguration
27 WORKDIR
=`mktemp -d -q "/tmp/${OUT}"`
29 echo "Could not create snapshot directory"
35 if [ -x /usr
/bin
/gzip ]; then
40 ARCHIVE
=`mktemp -q "${OUTDIR}/${OUT}.tar${GZ_EXT}"`
42 echo "Could not create snapshot archive"
55 # network interface configuration
57 ifconfig
-a -b > ifconfig
2>&1
60 # network route configuration
62 netstat
-n -r -a -l > netstat
2>&1
67 for if in `ifconfig -l`
71 en
* ) ipconfig getpacket
${if} > ipconfig
-${if} 2>&1
79 if [ -x /System
/Library
/PrivateFrameworks
/Apple80211.framework
/Resources
/airport
]; then
80 /System
/Library
/PrivateFrameworks
/Apple80211.framework
/Resources
/airport
--getinfo \
87 if [ -e /System
/Library
/CoreServices
/SystemVersion.plist
]; then
88 cat /System
/Library
/CoreServices
/SystemVersion.plist \
89 > SystemVersion.plist
2>&1
91 if [ -e /System
/Library
/CoreServices
/ServerVersion.plist
]; then
92 cat /System
/Library
/CoreServices
/ServerVersion.plist \
93 > ServerVersion.plist
2>&1
99 ioreg
-i -l -w 0 > ioreg
2>&1
100 ioreg
-i -l -p IODeviceTree
-w 0 >> ioreg
2>&1
105 hostname
> hostname
2>&1
110 hostinfo
> hostinfo
2>&1
111 if [ -e /etc
/hostconfig
]; then
112 cat /etc
/hostconfig
> etc.hostconfig
2>&1
118 scutil
--dns > dns
-configuration 2>&1
119 if [ -e /etc
/resolv.conf
]; then
120 cat /etc
/resolv.conf
> etc.resolv.conf
2>&1
122 if [ -e /var
/run
/resolv.conf
]; then
123 cat /var
/run
/resolv.conf
> var.run.resolv.conf
2>&1
127 # Proxy configuration
129 scutil
--proxy > proxy
-configuration 2>&1
132 # System / network preferences
135 /Library
/Preferences
/SystemConfiguration
/NetworkInterfaces.plist \
136 /Library
/Preferences
/SystemConfiguration
/com.apple.PowerManagement.plist \
137 /Library
/Preferences
/SystemConfiguration
/com.apple.airport.preferences.plist \
138 /Library
/Preferences
/SystemConfiguration
/com.apple.nat.plist \
139 /Library
/Preferences
/SystemConfiguration
/com.apple.network.identification.plist \
140 /Library
/Preferences
/SystemConfiguration
/com.apple.smb.server.plist \
141 /Library
/Preferences
/SystemConfiguration
/com.apple.wifi.plist \
142 /Library
/Preferences
/SystemConfiguration
/preferences.plist \
143 /Library
/Preferences
/com.apple.alf.plist \
144 /Library
/Preferences
/com.apple.sharing.firewall.plist \
147 if [ -e "${f}" ]; then
149 cat "${f}" > "${b}" 2>&1
156 ${PRIV} scutil
-p <<_END_OF_INPUT
161 if [ -f /var
/tmp
/configd
-store.xml
]; then
162 cat /var
/tmp
/configd
-store.xml
> configd
-store.xml
2>&1
164 if [ -f /var
/tmp
/configd
-pattern.xml
]; then
165 cat /var
/tmp
/configd
-pattern.xml
> configd
-pattern.xml
2>&1
167 if [ -f /var
/tmp
/configd
-session.xml
]; then
168 cat /var
/tmp
/configd
-session.xml
> configd
-session.xml
2>&1
170 if [ -f /var
/tmp
/configd
-state ]; then
171 cat /var
/tmp
/configd
-state > configd
-state 2>&1
175 # network reachability
177 scutil
-d -v -r www.apple.com
> reachability
-info 2>&1
178 if [ -x /usr
/bin
/dig -a -f /etc
/resolv.conf
]; then
179 /usr
/bin
/dig -t any
-c any www.apple.com
> dig-results 2>/dev
/null
183 # mounted filesystems
185 mount
> mounted
-filesystems 2>&1
190 if [ -f /var
/run
/mDNSResponder.pid
]; then
191 ${PRIV} kill -INFO `cat /var/run/mDNSResponder.pid`
195 # system log, kernel.log, early boot log messages
197 if [ -x /usr
/bin
/syslog
]; then
198 ${PRIV} syslog
| tail -n 25000 > syslog
199 if [ -d /var
/log
/DiagnosticMessages
]; then
200 ${PRIV} syslog
-d /var
/log
/DiagnosticMessages \
203 | tail -n 25000 > DiagnosticMessages
206 if [ -f /var
/log
/system.log
]; then
207 ${PRIV} tail -n 25000 /var
/log
/system.log
> system.log
209 if [ -f /var
/log
/kernel.log
]; then
210 ${PRIV} tail -n 25000 /var
/log
/kernel.log
> kernel.log
213 ${PRIV} dmesg
> dmesg
216 # IPConfiguration log
218 if [ -f /var
/log
/com.apple.IPConfiguration.bootp
]; then
219 ${PRIV} tail -n 2000 /var
/log
/com.apple.IPConfiguration.bootp \
220 > com.apple.IPConfiguration.bootp
226 scutil
<<_END_OF_INPUT \
230 if (index($2, "/") == 1) { print $2 } \
231 else { print "/var/log/ppp/" $2 } \
234 print "/tmp/pppotcp.log" \
240 show Setup:/Network/Service/[^/]+/PPP pattern
244 if [ -f "${logFile}" ]; then
245 b
="`basename ${logFile}`"
246 cat "${logFile}" > "${b}" 2>&1
251 # application firewall log
253 if [ -f /var
/log
/appfirewall.log
]; then
254 ${PRIV} tail -n 2000 /var
/log
/appfirewall.log
> appfirewall.log
258 # kernel extensions statistic
260 if [ -x /usr
/sbin
/kextstat
]; then
261 kextstat
> kextstat
2>&1
262 elif [ -x /usr
/sbin
/kmodstat
]; then
263 kmodstat
> kmodstat
2>&1
269 echo "#" > network
-statistics
270 echo "# arp -n -a" >> network
-statistics
271 echo "#" >> network
-statistics
272 arp
-n -a >> network
-statistics 2>&1
274 echo "#" >> network
-statistics
275 echo "# netstat -n -a -A" >> network
-statistics
276 echo "#" >> network
-statistics
277 netstat
-n -a -A >> network
-statistics 2>&1
279 if [ -x /usr
/sbin
/lsof
]; then
280 echo "#" >> network
-statistics
281 echo "# lsof -i -n -P" >> network
-statistics
282 echo "#" >> network
-statistics
283 ${PRIV} lsof
-i -n -P >> network
-statistics 2>&1
286 echo "#" >> network
-statistics
287 echo "# netstat -s" >> network
-statistics
288 echo "#" >> network
-statistics
289 netstat
-s >> network
-statistics 2>&1
291 echo "#" >> network
-statistics
292 echo "# netstat -mmm" >> network
-statistics
293 echo "#" >> network
-statistics
294 netstat
-mmm >> network
-statistics 2>&1
296 echo "#" >> network
-statistics
297 echo "# netstat -i -n -d" >> network
-statistics
298 echo "#" >> network
-statistics
299 netstat
-i -n -d >> network
-statistics 2>&1
301 if [ -x /sbin
/ipfw
]; then
302 echo "#" >> network
-statistics
303 echo "# ipfw -at show" >> network
-statistics
304 echo "#" >> network
-statistics
305 ipfw
-at show
>> network
-statistics 2>&1
308 if [ -x /usr
/sbin
/appletalk
]; then
309 echo "#" >> network
-statistics
310 echo "# appletalk -s" >> network
-statistics
311 echo "#" >> network
-statistics
312 appletalk
-s >> network
-statistics 2>&1
316 # system usage statistics
318 echo "#" > system
-statistics
319 echo "# uptime" >> system
-statistics
320 echo "#" >> system
-statistics
321 uptime
>> system
-statistics 2>&1
323 echo "#" >> system
-statistics
324 echo "# sysctl -a" >> system
-statistics
325 echo "#" >> system
-statistics
326 sysctl
-a >> system
-statistics 2>&1
328 echo "#" >> system
-statistics
329 echo "# zprint" >> system
-statistics
330 echo "#" >> system
-statistics
331 zprint
>> system
-statistics 2>&1
333 echo "#" >> system
-statistics
334 echo "# top -l5 -s2" >> system
-statistics
335 echo "#" >> system
-statistics
337 echo "Please wait, collecting statistics"
339 top
-s 2 -l 5 >> system
-statistics 2>&1
342 # DirectoryService info
344 if [ -x /usr
/bin
/dscacheutil
]; then
346 echo "# dscacheutil -configuration" >> ds
-info
348 dscacheutil
-configuration >> ds
-info 2>&1
351 echo "# dscacheutil -statistics" >> ds
-info
353 dscacheutil
-statistics >> ds
-info 2>&1
356 echo "# dscacheutil -cachedump -entries" >> ds
-info
358 dscacheutil
-cachedump -entries >> ds
-info 2>&1
362 # IPsec configuration
365 echo "# setkey -D" >> ipsec
369 if (/^(\s+[AE]:\s+\S+\s+)"?(.*)"?\s*$/) {
370 chop($sha1=`echo "$2" | openssl sha1`);
371 printf "%s[SHA-1:%s]\n", $1, $sha1;
379 echo "# setkey -Pp -D" >> ipsec
381 ${PRIV} setkey
-Pp -D >> ipsec
383 for CF
in /var
/run
/racoon
/*.conf
385 if [ ! -r "${CF}" ]; then
391 echo "# ${CF}" >> ipsec
395 if (/^(\s+shared_secret\s+use\s+)"?([^\s;"]+)"?(.*)/) {
396 chop($sha1=`echo "$2" | openssl sha1`);
397 printf "%s[SHA-1:%s]%s\n", $1, $sha1, $3;
405 # Kerberos configuration
407 if [ -x /usr
/bin
/klist
]; then
409 echo "# klist -e -c -A -f -a -n" >> kerberos
411 ${PRIV} klist
-e -c -A -f -a -n >> kerberos
2>&1
414 echo "# klist -e -k -t -K" >> kerberos
416 ${PRIV} klist
-e -k -t -K >> kerberos
2>&1
424 /usr
/bin
/dig @pm
-members.mac.com
-y "${DOMAIN}:${TSIG}" +short
"${1}" "${2}" 2>/dev
/null
427 scutil
<<_END_OF_INPUT \
428 | sed -n 's@.* : *\(.*\.members\.mac\.com\)$@\1@p' \
432 show Setup:/Network/BackToMyMac
437 echo "${DOMAIN}" >> btmm
439 # lookup TSIG in base64 format
441 ${PRIV} security find-generic-password \
443 -g /Library/Keychains/System.keychain 2>&1 \
444 | grep "^password: " \
448 if [ -z "$TSIG" ]; then
449 echo " No TSIG in system keychain." >> btmm
452 if [ `echo "$TSIG" | wc -l` -ne 1 ] ; then
453 echo " More than one TSIG in system keychain." >> btmm
457 KEYHASH
="[SHA-1:`echo ${TSIG} | openssl sha1`]"
459 echo " KEY: ${KEYHASH}" >> btmm
470 DIG
"${TYPE}.${DOMAIN}" ptr \
474 /bin
/echo " ${REG}" >> btmm
477 INF_Q
=`/bin/echo "${REG}" | sed -e "s/${TYPE}/_device-info._tcp/"`
478 INF
=`DIG "${INF_Q}" txt`
479 echo " INF: ${INF}" >> btmm
482 SRV1
=`/bin/echo "${SRV}" | head -1`
483 echo " SRV: ${SRV1}" >> btmm
484 SRV2
=`/bin/echo "${SRV}" | tail +2`
485 if [ -n "${SRV2}" ]; then
487 /bin
/echo "${SRV2}" \
488 | sed -e 's/^/ *****: /' >> btmm
492 TXT1
=`/bin/echo "${TXT}" | head -1`
493 echo " TXT: ${TXT1}" >> btmm
494 TXT2
=`/bin/echo "${TXT}" | tail +2`
495 if [ -n "${TXT2}" ]; then
496 /bin
/echo "${TXT2}" \
497 | sed -e 's/^/ *****: /' >> btmm
500 HOST
=`/bin/echo "${SRV}" | cut -d ' ' -f 4-`
501 if [ -n "${HOST}" ]; then
503 V6
=`DIG ${HOST} aaaa`
504 KRB
=`DIG _kerberos.${HOST} txt`
505 TUN
=`DIG _autotunnel._udp.${HOST} srv`
506 AT6
=`DIG _autotunnel6.${HOST} aaaa`
514 if [ -n "${V4}" ]; then
515 echo " v4: ${V4}" >> btmm
517 if [ -n "${V6}" ]; then
518 echo " v6: ${V6}" >> btmm
520 if [ -n "${KRB}" ]; then
521 echo " KRB: ${KRB}" >> btmm
523 if [ -n "${TUN}" ]; then
524 echo " TUN: ${TUN}" >> btmm
526 HOST
=`/bin/echo "${TUN}" | cut -d ' ' -f 4-`
527 if [ -n "${HOST}" ]; then
529 V6
=`DIG ${HOST} aaaa`
531 if [ -n "${V4}" ]; then
532 echo " v4: ${V4}" >> btmm
534 if [ -n "${V6}" ]; then
535 echo " v6: ${V6}" >> btmm
538 if [ -n "${AT6}" ]; then
539 echo " AT6: ${AT6}" >> btmm
546 # collect crash reports
553 mDNSResponderHelper \
561 /bin
/ls -1 /Library
/Logs
/CrashReporter
/${daemon}_
*.crash \
562 /Library
/Logs
/DiagnosticReports
/${daemon}/*.crash \
566 b
="`basename ${log}`"
567 ${PRIV} cat "${log}" > "${b}" 2>&1
572 # collect everything into a single archive
575 pax
-w ${GZ_OPT} -f "${ARCHIVE}" "${OUT}"
578 if [ ${UID} -eq 0 ]; then
579 if [ -n "${SUDO_UID}" -a -n "${SUDO_GID}" ]; then
580 if [ ${UID} -ne ${SUDO_UID} ]; then
581 chown
${SUDO_UID}:${SUDO_GID} "${ARCHIVE}"
586 echo "Network data collected to \"${ARCHIVE}\""
589 # if requested, generate a crash report
591 if [ "${OUTDIR}" = "/Library/Logs/CrashReporter/SystemConfiguration" -a "${1}" = "CRASH" ]; then