UNIX™ and Mac OS X

Die "Lingua Franca" des Programmierens (und fast aller Programmiersprachen) ist Englisch. Aus diesem Grund (und um mir Tipparbeit zu sparen) alles Weitere einsprachig.

This is a list of unrelated information regarding the UNIX™ underpinnings of Mac OS X. You should be familiar with Terminal.app and the basic concepts of a Shell.

General advice:

Getting the MAC address of a computer on your subnet

The MAC address has nothing to do with Macintosh, but identifies a network card on layer 2.

If you want to know the MAC address of the machine with, say, IP 192.168.0.123, type

 ping -c3 192.168.0.123
The result should look something like
 PING 192.168.0.123 (192.168.0.123): 56 data bytes
    64 bytes from 192.168.0.123: icmp_seq=0 ttl=64 time=8.387 ms
    64 bytes from 192.168.0.123: icmp_seq=1 ttl=64 time=5.354 ms
    64 bytes from 192.168.0.123: icmp_seq=2 ttl=64 time=4.297 ms

    --- 192.168.0.123 ping statistics ---
    3 packets transmitted, 3 packets received, 0% packet loss
    round-trip min/avg/max = 4.297/6.012/8.387 ms
Then type
 arp -a
Result:
 ? (192.168.0.123) at 0:0:c3:91:6b:c on en1 [ethernet] 

The part after "at" (0:0:c3:91:6b:c) is the MAC address you are looking for.

Schedule tasks

CronniX is a nice GUI for cron, the powerful unix tool that allows scheduled execution of shell scripts and applications. Freeware, Donations accepted.

Backup selected files / folders to a remote machine

Use RsyncX to sync, backup, distribute and schedule files. This version of rsync is fully aware of Resource Forks and type/creator, unlike the rysnc that comes with Mac OS X. Freeware.

However, if you want to backup to a remote machine with Mac OS awareness, there is a pitfall: It is necessary to tell the remote machine to use RsyncX instead of rsync by providing the path to the program. See the shell script in section Schedule / automate your backup for an example.

Automate remote login via ssh

In Terminal.app, enter
 sudo -s
and enter your password to get a root shell. Then run the command
 ssh-keygen -t rsa
and press Return in order to accept the default path you will be asked for. Next you will be asked for a passphrase. Enter Return twice for an empty one. Now you need to append your public key to the file "authorized_keys2":
 cd /var/root/.ssh
    cat id_rsa.pub >> authorized_keys2
Finally copy your .ssh folder to the remote machine, e.g. 192.168.0.123:
 cd /var/root/.ssh
    scp -r .ssh 192.168.0.123:/private/var/root/

That's it! For details, consult the man pages for ssh-keygen.

Schedule / automate your backup

Simply combine the functionality of RsyncX and CronniX.

If your backup is somewhat more demanding, call a shell script like the example given below in your crontab. The script does a sync, i.e. deletes files no longer present and logs progress / errors to a file named "Backup + current date".log in /var/log/ - where it belongs.

 #!/bin/sh

    LOGFILE=`date "+/private/var/log/Backup_20%y-%m-%d.log"`
    touch $LOGFILE

    echo >> $LOGFILE
    echo "Backup My1stFolder" >> $LOGFILE
    echo "+--------------------------------------+" >> $LOGFILE
    echo "| " `date "+Start am %d.%m.20%y um %H:%M:%S Uhr |"` >> $LOGFILE
    echo "+--------------------------------------+" >> $LOGFILE
    /usr/local/bin/rsync --rsync-path=/usr/local/bin/rsync --eahfs -az --showtogo --delete --stats /path/to/My1stFolder 192.168.0.123:/path/to/1stBackup/ 1>> $LOGFILE 2>> $LOGFILE
    echo "+----------------------------------------+" >> $LOGFILE
    echo "| " `date "+Beendet am %d.%m.20%y um %H:%M:%S Uhr |"` >> $LOGFILE
    echo "+----------------------------------------+" >> $LOGFILE

    echo >> $LOGFILE
    echo "Backup My2ndFolder" >> $LOGFILE
    echo "+--------------------------------------+" >> $LOGFILE
    echo "| " `date "+Start am %d.%m.20%y um %H:%M:%S Uhr |"` >> $LOGFILE
    echo "+--------------------------------------+" >> $LOGFILE
    /usr/local/bin/rsync --rsync-path=/usr/local/bin/rsync --eahfs -az --showtogo --delete --stats /path/to/My2ndFolder 192.168.0.123:/path/to/2ndBackup/ 1>> $LOGFILE 2>> $LOGFILE
    echo "+----------------------------------------+" >> $LOGFILE
    echo "| " `date "+Beendet am %d.%m.20%y um %H:%M:%S Uhr |"` >> $LOGFILE
    echo "+----------------------------------------+" >> $LOGFILE

    echo >> $LOGFILE
    echo "+ooooooooooooooooooooooooooooooooooooooooo+" >> $LOGFILE
    echo "| " `date "+Komplett am %d.%m.20%y um %H:%M:%S Uhr |"` >> $LOGFILE
    echo "+ooooooooooooooooooooooooooooooooooooooooo+" >> $LOGFILE 

Make your own Contextual Menus

The freeware OnMyCommandCM is one of the most powerful contextual menu plug-ins, it executes UNIX CLI commands, Shell Scripts and AppleScripts.

There are hundreds of commands submitted by users available online, it is like having hundreds of different contextual menu plug-ins to choose from!

Lock / Unlock all files in a folder

In Terminal.app, enter
 chflags -R uchg /path/to/file/or/folder
to lock, respectively
 chflags -R nouchg /path/to/file/or/folder
to unlock a file or all files in a folder (and its subfolders).

Easier yet: get OnMyCommandCM and download command #112.

Restart / Shutdown a remote machine

In Terminal.app, enter
 ssh YourUserName@192.168.0.123
to open a ssh session to 192.168.0.123, you'll be prompted for a password, provided ssh access is activated on the remote machine. If a connection is established, enter
 sudo reboot
in order to restart the machine or type
 sudo shutdown -h now
to shutdown. Very handy if you are running time consuming tasks and want to shutdown the machine remotely when done. I use it to shutdown my machine at work from home (via VPN) without wasting another Timbuktu activation key.

Check Preference Files

In Terminal.app, enter
    plutil /Library/Preferences/*.plist
to check all your preference files for syntax errors.

Easier yet: get OnMyCommandCM and download command #17.