Browsing TagMac OS X

Bourne Shell Logging Routine

Here’s another logging routine, this one is written in Bourne shell:

#!/bin/sh

log_message() {
    echo `date "+%m/%d/%y %H:%M:%S %Z"` "$1" | tee -a aaa.out
}

log_message "Hello there"
log_message "Goodbye"

Sample output:

08/28/07 23:16:13 EDT Hello there
08/28/07 23:16:13 EDT Goodbye

 

Determining the External IP Address

Here’s how to find out your external IP address courtesy of this hint:

http://www.macosxhints.com/article.php?story=20060602180942480


curl --silent http://checkip.dyndns.org
    | awk '{print $6}' | cut -f 1 -d "<"

If you are using Apple’s Airport Extreme Basestation (mine is particularly the Time Capsule and this is where I have tested this), and you have the SNMP interface enabled, you can run the following command


prompt$ snmpwalk -Os -c public -v 1 192.168.63.1 ipAdEntAddr IpAddress 
    | grep -E -v '(127.0.0|169.254|192.168.63.1)' 
    | cut -d : -f 2 | sed 's/ //g'

Line Terminations

Line terminations for different operating systems:

unix 0x0a LF
Classic Mac 0x0d CR
Windows 0x0d 0x0a CR LF

To convert a text file with DOS line termination to UNIX line termination:


tr -d '15'  unixfile.txt

or


sed s/.$// winfile.txt > unixfile.txt

To convert a unix file to a DOS file:


sed s/$/x0d/ unixfile.txt > winfile.txt

Run Periodic Maintenance Scripts Manually

Mac OS X has to run some maintenance scripts in the middle of the night to do some important housekeeping tasks. If you have a Mac that sleeps in the middle of the night, as you do, you need to run these manually by running this from the shell:


sudo periodic daily weekly monthly

Change Behavior of iTunes Arrows

Starting with iTunes 4.5, Apple implemented those little grey arrows next to the song title, artist, and album, which will take you to the corresponding match in the iTunes Music Store. To change the behavior of these arrows so that instead of going to the store, it will take you to your library instead, you can do either one of two ways:

  1. Hit option key when you click the arrow.
  2. Change it permamnently by executing this from the terminal:

    defaults write com.apple.iTunes invertStoreLinks -bool YES

    
    

    Make sure iTunes is not running when you execute this command.