Murphy Mac - Screencasts and Tutorials » Posts in 'Terminal' category

Dropbox, SSH, and iPhone

Mrs. Murphy called and said she wanted to download a file from a Mac back home to her Macbook Air on the road. Away from the house I thought for a second about the easiest way to send her the file. I flicked through my iPhone apps and saw a simple solution.

My iPhone has both TouchTerm and Dropbox (syncs a local folder to the cloud) installed. TouchTerm let me ssh into the Mac at the house which was awake and recording a television show. From there a simple copy command let me copy the file into my Dropbox public folder. That was the hardest part.

Once the file copied over I launched the Dropbox app on the iPhone. The file was listed in my Dropbox public folder – allowing me to use the mail-a-link function in the app. Mrs. Murphy got the email, clicked the link to download her file – and she was all set.

Back when Murphy had more time to tinker he came up with far crazier solutions, like Retrieve a File on Your Mac by Email. Which is still great if you’re up against certain firewall restrictions or other obstacles. Better yet, that solution would have worked as soon as the Mac woke up, had it been asleep.

But this solution required far less preparation. I had ssh running on the remote Mac, and Dropbox was installed on both the Mac and my iPhone. That’s it. I could have used the Dropbox web interface instead of the app.

I realize there are other solutions Mrs. Murphy could have used. Logmein. FTP. VNC. Etc. Everyone has their preference, but I found this direct and efficient.

What do you think?

Get Dropbox | Permalink

Create an openssl Function

Remote Login With SSHThis is a quick way to make encrypting files using the terminal fast and convenient. Murphy posted instructions on making an interactive shell script to do essentially the same thing. This is a slightly different spin. Skip ahead to the screencast to see how easy file encryption can be. The openssl command we’re using is included with OS X.

Like other things we’ve covered – the specific example might not apply to you – but for people who’ve never used a function it might be helpful. Functions can make complicated Terminal commands more convenient to use.

To create the function just add this line to the .bash_profile file in your home directory:

des3() { openssl des3 -salt -in "$1" -out "$2"; }

Note that there’s a space after the opening curly bracket and a space before the closing curly bracket. All we need to remember is the function name, and to provide two file names: one to encrypt and one to be the output file.

The breakdown on the command: the first des3 is what we named the function. We can name it anything but des3 is what Murphy chose. The name of the function is what you’ll type whenever you use it.

The stuff in the curly brackets is what happens when we invoke the function. See this post for more on the openssl command.

The des3 following the openssl command is the type of encryption we’re using. It’s part of the openssl command syntax. We added $1 and $2 after the in and out respectively because they’re the two pieces of information we need when we invoke our function.

The $1 and $2 will be replaced with the paths we type into Terminal. In the screencast Murphy shows how to invoke the function. Instead of typing the paths he drags the file to be encrypted into the window – which saves us the typing. He also names the output file with a des3 extension to remind himself how he encrypted the input file.

As always, be careful with the Terminal if you’re not familiar with it. See Murphy’s warning about the dangerous possibilities.

Watch Screencast | Permalink


I’ve avoided the tar command for some time now, only to find there’s nothing to be afraid of.  My Windows background always led to pkzip for compression and archiving.  Knowing that zip shipped with OS X there wasn’t really a need to look any further.

But sometimes you’re sent things in the tar format.  Or the even more mysterious tar.gz.  If you have no experience with Linux or Unix the tar command and tar.gz files might leave you confused. Before OS X the only experience Murphy had with Linux was hacking a Directv TiVo so he could install a bigger drive.

Anyway – OS X makes tar and tar.gz files simple to work with.  Double-click one in the Finder and its contents are extracted.  But what if you want to create one?  Or see what’s inside before you open it?  We’ll do both of those things in the screencast, but here’s a quick overview of some tar basics.

tar -cvf irl08.tar Pictures/ireland_08

That command will create an archive called irl08.tar in the current directory.  All the files inside the ireland_08 directory will be placed inside, without compression.  The c creates the archive, the v displays progress as files are added, and the f specifies a file as the destination.  (tar stands for tape archive)

tar -zcvf irl08.tar.gz Pictures/ireland_08

This command is almost exactly the same, but the z option compresses the archive so we’ve added the customary gz to the file name.

Here’s how to view the contents of a tar archive:

tar -tvf irl08.tar

The t option lists the files.  If your archive is compressed add a z option too.

How does tar compare to zip?  Murphy isn’t sure what all the differences are.  He compressed a directory with dozens of screencasts in it using both utilities.  The resulting archive was about the same size for each.  The screencasts were already compressed themselves, so they might not be the best test subject.

A little research shows that extracting a single file from a very large archive might be quicker with zip than with tar.  A zip file includes a table of contents that makes locating an included file more direct.  And a zip file compresses the included files individually as they’re added.  A tar.gz file creates the archive first and then compresses the whole thing at once.  That can make single file extraction more time consuming as the entire large archive must be opened up.

There’s also gzip for compressing files.  But gzip deletes your original file, replacing it with the compressed one.   That makes Murphy a little nervous.  tar leaves your original files in place, so you can delete them if you need to.

tar.  One less thing to be afraid of.

You might find these posts interesting:

command line encryption

Watch Now | Permalink

Get More From Hotel Wifi

ipod touch

Using multiple devices with paid hotel Internet access.

This weekend I used the Internet at a hotel that charged for access. I signed up using my iPod, then later tried to access the service using a laptop. The sign-on page didn’t provide a place to sign in using my name or room number – it seemed like I might be charged again if I went any further. I had never seen the particular service before, so I couldn’t tell what would happen.

I didn’t feel like calling the front desk, and chances are I wouldn’t have had much faith in whatever they told me. Sounds cold, but it’s true. The solution I found was probably faster anyway.

I assumed the hotel tracked my iPod by its MAC address. If you’re not familiar with a MAC address, it’s a unique identifier assigned to network devices like your wired Ethernet port or a wifi card. (MAC addresses are not to be confused with Macs) Some software interfaces provide a simple way to change the MAC address your device presents to the network. I didn’t see a simple way in System Preferences.

A quick Google search landed me at OS X Daily. There you’ll find the exact command to enter in Terminal to change your MAC address. You may have to tweak the command a little if you’re using multiple network interfaces on your Mac, like wired and wireless.

So, I took the MAC address of my iPod and assigned it to the laptop. I didn’t try to use both at once, and both worked just fine. As soon as the MAC was changed on the laptop it was on the Internet, without having to access any special sign-up page for the service.

At some point hotels will probably update their services to help with a situation like this, but in the meantime OS X Daily helped me out in less than two minutes. Nice.

Read | Permalink

Twitter While You Sleep

TwitterWait until you see what a clever pun this title is. Using the sleep command in Terminal you can update your Twitter status while you’re away. Or sleeping.

Apple has jumped around a little with regards to command line scheduling tools, but the sleep command is still dead-simple to use. (Read more about scheduling with lingon and launchd here)

Suppose you have a command you want to run once, at a future time. Use sleep followed by the number of seconds to wait. Then use a semi-colon to separate the command to run at the appointed time.

sleep 30 ; command

The above example will execute command 30 seconds after you hit the return key. 3600 seconds is an hour. 86,400 seconds in each and every day.

So now you just need a command to update Twitter. The curl command comes with your Mac. Twitter Development Talk boasts the easiest way to update Twitter from the command line. Scroll down to The Easiest Way to Play Around with the Twitter API. Christopher Penn has a post on it too, but the command is cut-off on his blog.

The command should look like this:

curl -u username:password -d status=”your message here”

Enter that all on one line. It would be better to make it into a shell script. Just copy that line into a text file, maybe name it, and replace the your message here part with $1. Then use chmod to make it executable.

Note: Don’t know how to make it executable? Read more about making a shell script. Learn even more about shell scripts: make an interactive shell script.

From there you can enter the following in the Terminal:

./ “Looking into starting my own airline…”

And you’ve updated your Twitter status.  You can make that cleaner by setting an alias for your shell script.

Finally, to have your tweet post onto Twitter hours later you could enter something like this in the Terminal:

sleep 7200; ./ “I’m sleeping” (you’ll need to leave your Mac on)

If you’re a stickler about your Twittering and want to be accurate, this is the way to go. Schedule that I’m in the shower tweet in advance. People need to know.

| Permalink