January 2010 Archives

find exec mv

| 0 Comments
Everyday commands
find . -name *.zip -exec mv {} /tmp/. \;

Disable transmitting Bonjour service advertisements on Mac

| 0 Comments

Referenced: http://support.apple.com/kb/HT3789

---

Disable transmitting Bonjour service advertisements. You can use this advanced article if you are a network administrator who needs to disable Bonjour advertising service without disabling Bonjour queries and DNS.

Products Affected

Bonjour, Mac OS X 10.6, Bonjour

Important: Follow these steps carefully. A malformed or problematic mDNSResponder.plist file may prevent your Mac from starting up. As a precaution, perform a full backup of your system with Time Machine.

  1. Make a back up copy of the mDNSResponder.plist file as a precaution.
  2. Open the mDNSResponder.plist file in Terminal using your preferred text editor. Here is a sample command:
    sudo nano "/System/Library/LaunchDaemons/com.apple.mDNSResponder.plist"
  3. Add "<string>-NoMulticastAdvertisements</string>" to the array in the "ProgramArguments" section.

    In other words:
       <key>ProgramArguments</key>
  4.    <array>
  5.        <string>/usr/sbin/mDNSResponder</string>
  6.        <string>-launchd</string>
  7.    </array>

  8. becomes...
       <key>ProgramArguments</key>
  9.    <array>
  10.        <string>/usr/sbin/mDNSResponder</string>
  11.        <string>-launchd</string>
  12.     <string>-NoMulticastAdvertisements</string>
  13.    </array>

  1. Save the file.

    Important
    : If you edited the file using emacs, you must remove the emacs backup file (the file with a tilde at the end of the name, "/System/Library/LaunchDaemons/com.apple.mDNSResponder.plist~") or your Mac will not start up.
  2. Restart your Mac.


   or


launchctl unload -w /System/Library/LaunchDaemons/com.apple.mDNSResponder.plist

launchctl load -w /System/Library/LaunchDaemons/com.apple.mDNSResponder.plist


Additional Information

Prior to Mac OS X v10.6, the only way for a network administrator to disable Bonjour advertising of services was to completely disable the mDNSResponder process, which also disabled Bonjour discovery of services (such as discovering network printers).


Jumbo Frames & Oracle

| 0 Comments
Ethernet uses a Maximum Transfer Unit (MTU) of 1,500 bytes. This limits the maximum size of an Ethernet packet to 1,500 bytes. Larger I/O requests are split into multiple MTU-sized packets. Transmitting a large number of small packets impacts the host CPU by generating an excessive number of interrupts for each application I/O.
Typical database environments transfer data in 2KB to 32KB sizes which always require multiple 1,500 byte packets per database I/O. Jumbo frames increase the device MTU size to a larger value (typically 9,000 bytes) allowing I/O requests to more frequently fit in one physical packet and reducing the number of frames required for larger I/O requests.

Starting VMware Fusion from the Command Line

| 0 Comments
open /Applications/VMware\ Fusion.app/Contents/MacOS/vmware

Ping Success or Failure using Bash

| 0 Comments
#!/bin/bash

if ping -c 1 hostfoo > /dev/null
   then
	echo "ping success"
   else
        echo "could not ping hostfoo. exiting..."
fi

Automating SSH public key pushes with Perl

| 0 Comments

Automating SSH public key pushes to servers.

The code below uses Expect and SSH to create & permission the .ssh directory. Followed by SSH copying the local temp file as the authorized_keys file to the .ssh subdir on the target server .

Be sure to set StrictHostKeyChecking=no in the SSH client side config.

---

#!/usr/bin/perl

use strict;
use warnings;
use English;
use Expect;
use Net::Ping;
my $username = "USER";
my $password = "PASS";
my $homedir  = "\/export\/home\/$username";
my $ssh_dir  = "$homedir\/.ssh";
my $ssh_pub  = "
ssh-dss BLAH BLAH use your own public key file entry here.
";

if ( ! $ARGV[0] ) {
        print "$0  \n";
        exit
} 

my $host = "$ARGV[0]";
my $p 	 = Net::Ping->new();
if ( $p->ping($host) ) {
	print "Deploying public key to $host \n";
	create_ssh_dir();
	chmod_ssh_dir();
	push_ssh_key();
} else {
	print "Seems $host is not reachable \n";
}
$p->close();

sub create_ssh_dir {
my $ssh_cmd  = "/usr/bin/ssh $username\@$host 'mkdir $ssh_dir'";

my $timeout  = '5';
my $exp      = Expect->spawn($ssh_cmd) or die "Cannot spawn ssh command \n";
$exp->expect($timeout, ["Password:"]);
$exp->send("$password\n");
$exp->soft_close();
}

sub chmod_ssh_dir {
my $ssh_cmd  = "/usr/bin/ssh $username\@$host 'chmod 755 $ssh_dir'";

my $timeout  = '5';
my $exp      = Expect->spawn($ssh_cmd) or die "Cannot spawn ssh command \n";
$exp->expect($timeout, ["Password:"]);
$exp->send("$password\n");
$exp->soft_close();
}

sub push_ssh_key {
my $tmp_file  = "/tmp/authorized_keys.$$";
chomp $ssh_pub;

open  ( AUTHKEY, ">$tmp_file") || die ("Unable to create $tmp_file\n");
print AUTHKEY "$ssh_pub" . "\n";
close ( AUTHKEY );

my $scp_cmd  = "/usr/bin/scp $tmp_file $username\@$host:$ssh_dir/authorized_keys";

my $timeout = '5';
my $exp = Expect->spawn($scp_cmd) or die "Cannot spawn scp command \n";
$exp->expect($timeout, ["Password:"]);
$exp->send("$password\n");
$exp->soft_close();

unlink("$tmp_file");
}

Write Chinese Characters using Trackpad on Mac

| 0 Comments

From http://www.apple.com/macosx/refinements

Innovative Chinese character input.

Until Snow Leopard, if you wanted to enter Chinese characters on a computer, you had to type in the phonetic spelling of Chinese words and the computer would convert them into proper Chinese characters. Snow Leopard offers a breakthrough new way to enter characters: You write them directly on the Multi-Touch trackpad in your Mac notebook. They’ll appear on the screen in a new input window, which recommends characters based on what you drew and lets you choose the right one. The input window even offers suggestions for subsequent characters based on what you chose.


Mac Chinese Trackpad