Archive for the ‘Terminal’ Category

Compacting Sparse Image Files

Friday, January 11th, 2008

Compact a Sparse ImageMurphy has been using SuperDuper for backups for a while now. Its flexibility and ease of use have helped it build up quite a following. Usually, Murphy sends his SuperDuper backups to a sparse image file. The sparse image file is a container that grows as you add more content. But what if content is removed from the sparse image file? That’s a good question.

The answer is that the sparse image file needs a little help to shrink. For example, let’s say you backed up your drive on Wednesday to a sparse image file. Then you deleted some big video files on Thursday and did another backup with SuperDuper on Friday. Your video files aren’t in the sparse image file anymore, but the backup is still taking up space on disk as if they were. The solution is simple. Use a simple command in the Terminal to reclaim the wasted space in your sparse image file. Just type everything in the line below, replacing the path and file name with the path and file name of your sparse image. (more…)

SuperDuper Developer's Site

Schedule a Command without Cron

Thursday, January 3rd, 2008

cron alternateIf you only have a few minutes to schedule a job you might not feel like digging into cron for your kickoff tool - especially if you’ve never used it before. In fact, Apple is kind of discouraging the use of cron in favor of launchd these days.

If you came from Windows you might be happy to see OS X has the AT command you might be oh-so-familiar with. Until you realize Apple doesn’t really want you using that either. That’s a shame, because AT is quick and dirty and supports some simple syntax, like now + 3 hours, to set a time for kickoff. In fact, you can specify teatime as a time, which really means 4pm.

If you’re sleepy and want to schedule a job and you don’t want to mess around, iCal might be the answer. You can use the alarm feature of an appointment to run an Applescript. Just set the time and pick your script like you see in the picture.

cron alternative

Your script can be pretty simple. Something like the screenshot below should work. Just replace the text following “do script” in the double quotes with whatever your terminal needs require.

cron alternative

The articles linked above mention the downsides of cron and AT - mostly dealing with sleeping machines and hard drives that can’t rest because AT is frequently checking to see if it has anything to do. That’s why OS X doesn’t enable AT by default. If your machine will be sleeping when you need the command to run you can wake it up with the Energy Save in System Preferences.

No screencast for this one. If you want to shed any light on how you schedule your routine jobs let us know in the comments. As always, be careful with the Terminal. You can break something very easily!

More on Applescript

Exit Your SSH Session Without Killing Your Job

Monday, December 31st, 2007

screen commandMurphy loves this one. If you connect to a remote machine and kick off something like a file copy you have to stay connected to the remote machine for the job to complete. Unless you use the screen command, which lets you detach from the running session while your job chugs away.

This is great for a process that might take a long time to complete. Murphy can use his hacked ipod touch to ssh to a remote machine, tell it to start copying files, detach, then turn the touch off. The screen command will even let you reconnect to the remote machine to check the progress of the job.

In the screencast Murphy covers how to get screen going, and how to switch between active screens and close them down. There’s plenty of other information on screen if you look around.

With screen running you can hit CTRL-A and then a key to issue a screen command. For example, CTRL-A followed by D lets you detach from a screen without closing it. Murphy also uses CTRL-A followed by ” (double-quote key) to get a list of screens he can switch to. Follow the link above for more screen tips. Or take a look at the screencast.

Watch Now

Interactive Shell Script: Command Line File Encryption

Thursday, May 10th, 2007

openssl encryptionIn today’s installment of Terminal Thursday we’ll be encrypting a single file from the command line courtesy of an excellent tip from the guys over at OSXDaily. The openssl utility ships with your Mac - and it’s pretty easy to use.

An OSXDaily reader posted a comment asking if there was a drag and drop way to encrypt a file. We’ve got a solution - sort of. Murphy sees this as a perfect place to introduce a shell script that prompts the user for input. Just kick off the shell script and you’re prompted for the file you want to encode. You can drag the file onto your Terminal window and hit enter. You’ll be prompted to set a password and you’re done.

You could make a similar shell script for decrypting the files too. And you’re not stuck with Murphy’s method, which dumps the output in a pre-configured folder. You could concatenate an extension onto the encrypted filename instead. Whatever works for you.

The screencast assumes you’ve seen Murphy’s post about making a shell script, so you might want to check that one out before getting started. It also introduces basename - which helps us extract a file name from a full path.

A word of warning from the original post: Don’t forget your password. Chances are you’re not going to find a way to break triple-des security.

UPDATE:  Carry out this process with a Widget.

Watch Now

Secure Browsing With An SSH Proxy

Friday, May 4th, 2007

Your Mac makes it easy to browse the web using a secure connection to a proxy. There are a couple of reasons you might want to do something like this:

  • You’re working at a company that has blocked access to certain sites
  • You’re using a wifi hot-spot and you think the provider might be snooping
  • You don’t want your work IT guys watching your traffic.
  • You’re having unresolvable problems connecting to Internet resources from your current location.

Lifehacker posted complete instructions on how to configure Firefox to use an SSH session for all its activity. There are only two steps. One is to change a preference in Firefox. The other is to initiate the SSH session using the N and D options - which together listen for a specified port on your machine and send the corresponding traffic to the proxy - which is the machine at the other end of your SSH connection.

SSH ProxyThe proxy (maybe a machine at your house or your hosting provider) actually retrieves the web pages you want using its Internet connection, then sends them to you over the encrypted channel. The provider at your location can’t see what you’re browsing, they just see that you’re connected to a remote computer using SSH.

If you’ve got a Mac at home that you can leave on you can use it for this purpose. But it’s not ideal. Most residential ISPs don’t deliver good upstream speed. Everything you want to see will first be downloaded and then uploaded by the machine at your house.

Murphy’s hosting provider allows SSH access. That’s a valuable thing in a host for many reasons - and it allows you to use their machine(s) as your proxy. You’ll probably get much better bandwidth going that route. Nice pun.

In the screencast Murphy uses a domain name instead of the external IP of his home machine. This is accomplished through an entry in the hosts file. He also mentions using ssh, securely, without passwords. There’s a screencast on that too.

Sidenote: Murphy started creating this screencast at Panera and realized the G5 at home (which can accept an SSH connection) was asleep. But there’s a Windows machine that’s always on in the basement - and it can be contacted to wake up other machines on the home network. You could do something like this with Mail rules - or just use Chicken of the VNC.

Watch Now