Web Admin Blog Real Web Admins. Real World Experience.


SSH on a Mac Errors with “Write Failed: Broken Pipe”

Recently I had an issue when moving to a new Mac on OSX when I was trying to SSH to a Linux server.  It would make the initial connection and then prompt me for a password.  Once I entered the password, however, it would just hang (ctrl+c wouldn't even escape out) until eventually it would break to the command line with the message "Write Failed: Broken Pipe".  After digging through various posts online, most of which were referring to timing out due to inactivity, I finally found a winner.  I edited the /etc/sshd_config file and set the ClientAliveInterval value to 300.  Then, I rebooted my Mac.  The next time I tried to SSH to the same server, everything connected as expected.  I hope this helps someone else in the future who is running up against the same issue I had.


Stupid Unix Trick – Command Mashups

I've been a *nix Administrator in some form or fashion for about 10 years now.  I remember back when I was first learning commands and how the OS works and every once in a while I'd come across something stupidly simple yet extremely useful to put in my bag of tricks.  Yesterday I was reminded about one of those things and I figured I'd share it here so that you can throw it in your bag of tricks as well if it's not already in there.

To start out, let me illustrate the problem.  You are writing a shell script or running a series of commands on the CLI.  Let's just say it's something simple like creating a new directory, changing to that directory, and then creating a file.  When I first started out, that command would look something like this:

mkdir newdirectory; cd newdirectory; touch newfile

The problem with this is that each command is executed on it's own regardless of whether or not the previous command was successful.  So if, for example, my mkdir and cd failed (permissions maybe?), I would be creating that newfile in whatever directory I started out in.  At best, I just created a new file in the wrong directory.  At worst, if the file which I'm creating was the same name as another file already in the current directory, I just overwrote it.  Not good!

The way to fix this is to add a dependency so that each command will not execute without the successful return of the command before that.  The way you do this is by putting an "&&" between them instead of the semi-colon.  So now the command string above should look like this:

mkdir newdirectory && cd newdirectory && touch newfile

Now you have guaranteed that the new file will not be created with the touch command unless both the mkdir and cd commands before it are successful.  Stupid simple, right?  Enjoy!