Categories

 

January 2012
M T W T F S S
« Oct    
 1
2345678
9101112131415
16171819202122
23242526272829
3031  

What I'm Doing...

PlaytimePriya and KunalIMG00015.jpgIMG00017.jpgFallColors.jpgSpring

Tandoori Style Butter Chicken at Trader Joe’s

20111019-000337.jpg

Share

Time Machine backup to an SMB share

If you wanted Time Machine to work with a SMB share you will notice that it doesn’t work. To get it to work run the following command on the terminal

defaults write com.apple.systempreferences TMShowUnsupportedNetworkVolumes 1

Now mount your SMB share. The best way to do this is to click on Go->connect to server in the finder menubar. For the server name you enter smb://username:password@servername/ShareName. I have a NAS share which has a Guest account with no password so my address looks like smb://Guest:@MyServer/HomeShare/TimeMachineBackup. Notice I have no password as no password is required for the Guest account.
Once mounted, Control click on the Time machine in the Dock and select “Time Machine Preferences”. Once you select “Choose Backup Disk” you should see your SMB Share. Select your SMB share and start your Time Share.
Once Time Machine backup starts, you will see an error saying that it cannot create image error. This error message was expected as Time machine could not create a file called a sparsebundle which is required for it to work on the SMB share. For this to work correctly we will be creating the sparsebundle manually. Turn off Time machine and go on to the next step.

In your terminal find your mac address. You can do this with the following command

ifconfig en0 | grep ether

Make a note of the mac address without the colon symbol. For this example lets assume my MAC address is 000000000000. Decide on how big you want your Time Machine backup to be. Then run the hdiutil command to create your sparsebundle file. Here is the command I created for a 200 Gigs share -

hdiutil create -size 200g -fs HFS+J -volname “OSX Backup” mymac_000000000000.sparsebundle

Where 000000000000 is my mac address and mymac is my mac name.

Now copy the sparsebundle file to the Nas share you want for your backups. In my case I copied it to the TimeMachineBackup folder on my NAS Share.

Go back to Time machine preferences and turn on Time machine. You should now see that the backup starts up with no problems. Depending on what you are backing up, the first time it runs it might take some time.

An important point to note is that for this to work your NAS Share needs to be mounted. You can set Time machine to be manual so that way you can make sure your SMB share is mounted before you click on the backup button.

Share

Super Secret features and shortcuts for your MAC

http://mac.appstorm.net/how-to/os-x/30-super-secret-os-x-features-and-shortcuts/

Share

terminal tips and tricks for Mac OS X

Some interesting tips and tricks for Mac OS X
http://apple.stackexchange.com/questions/5435/terminal-tips-and-tricks-for-mac-os-x

Share

Mac Book Pro terminal prompt keeps changing

It got really annoying for me to see how my terminal prompt kept changing when I connected my Macbook from work. I know I can easily fix this by setting my prompt in my .profile file, but I wanted to find out why this was happening.

It turns out the culprit is DHCP. By Default the hostname is determined dynamically on your macbook. This setting can be controlled with your /etc/hostconfig file. Here is what it looks like on my laptop -

# This file is going away

AFPSERVER=-NO-
AUTHSERVER=-NO-
TIMESYNC=-NO-
QTSSERVER=-NO-

To hard code a hostname, I just added “HOSTNAME=MyMacBook” (without the quotes) to the end of the file.
Some might consider the changing hostname a feature they might want. Not me ;)

Share

Convert uploaded file with windows line ending to unix line ending using php

I was working on a php project which involved in uploading a tab delimited file and then processing it with php on a unix webserver to insert data into a database. The file was produced on a windows machine and so it had windows line endings. I used this trick to strip off the carriage return and line feed characters from each line of the file

Here is my html form code

	<form action="process.php" method="post" enctype="multipart/form-data" name="import_form">
		<input type="hidden" name="action" value="import">
		<input type="file" name="import_file">
		<br>
		<input type="button" value="Import">
	</form>

Here is my code for process.php

if(isset($_POST['action']) && ($_POST['action'] == 'import')) {
	if (is_uploaded_file($_FILES['import_file']['tmp_name'])) {

		//	Move the file into an accessible location.
		$buffer = trim(implode("",file($_FILES['import_file']['tmp_name'])));

		// Convert all line-endings to UNIX format
        $buffer = str_replace("\r\n", "\n", $buffer);
        $buffer = str_replace("\r", "\n", $buffer);

        //code for processing $buffer

	else {
		echo "<p class=\"Error\">File Upload Failed.</p>";
	}
}
Share

Argument list too long

Ever tried to copy or move a bunch of files on unix/linux from one location to another and see this error message spit out back at you??

$ cp /var/www/* /var/tmp
-bash: /bin/cp: Argument list too long

UNIX find to the rescue…

$ find /var/www -type f -name '*' -exec cp {} /var/tmp/. \;

problem solved!

Share

MAMP - mysqlcheck: Got error: 1045

I started seeing the following error every time I started MAMP. This began after I changed the root password for my MAMP installation on my MBP.

/Applications/MAMP/Library/bin/mysqlcheck: Got error: 1045: Access denied for user 'root'@'localhost' (using password: YES) when trying to connect

It turns out that the default password is hard coded in different scripts under ‘/Applications/MAMP/bin’. In my case the script quickCheckMysqlUpgrade.sh. Just edit the script to have the correct password and you wont see the annoying message again.

Share

Join multiple mpg files into one file

I did not realize how easy it is to join mpeg files with just the windows copy command or unix cat command.

On windows the trick is to copy the files while preserving the binary format. Here is how you would do it -

copy files1.mpg /b + files2.mpg /b joinedfile.mpg

You could also do the following if the files are named consecutively

copy file*.mpg /b joinedfile.mpg

On UNIX it couldn’t be any simpler..

cat file1.mpg file2.mpg > joinedfile.mpg

or

cat file*.mpg > joinedfile.mpg
Share

SSH aliases

I constantly connect to linux or unix machines using ssh and it can get a little bothersome typing out the IP address repeatedly. Here is the typical syntax to connect to a linux box (random IP address)

ssh username@111.11.11.1

Now imagine typing this again and again. Thats where the ssh config file comes to the rescue. You can create aliases to make your connections easy. The template for the config file ~/.ssh/config is

Host domain
  HostName domain.com
  User username

The HostName can be either an IP address or an actual hostname. So for our example above our config file ~/.ssh/config will be

Host myserver
  HostName 111.11.11.1
  User username

So now all you have to do is type the following on your command prompt to directly connect and get prompted for a password.

ssh myserver

You can create as many aliases as you want. You can also override the settings of the config file on the command line. For instance if you want to connect using a different user, you can do the following

ssh diff_user@myserver

You can also specify your SSH keys for the server in your config file as shown below so you don’t have to enter your password

Host myserver
  HostName 111.11.11.1
  User username
  IdentityFile ~/.ssh/id_dsa

Click here or here to read how to generate and use SSH keys.

Share