Tuesday, June 30, 2009

Screen Utility (and my .screenrc)

Screen is a fantastic utility which is best described as a terminal multiplexer.  It comes standard in most modern Unix-based operating systems (e.g. Linux, MacOS X, BSD).  Simply stated it is one of the most useful utilities I have discovered and is a powerful tool in the hands of a console warrior.

In a nutshell: you can run any number of console-based applications within a single terminal.  I usually fire up one terminal and then ssh to various hosts.  But one of the best features is the ability to decouple the terminal emulator from the running programs.  This means you can log out or loose your session accidentally and you can come right back to where you are.

This if fantastic for embedded development.  I ssh to a workstation (Linux) attached to the embedded console over a USB serial port.  This is running 24 hours a day monitoring the embedded system.  I ssh to the workstation and use screen to reattach to the running serial console. I wrote about this HERE.

Basic screen commands

Control-A Control-C will create a new session/shell.

Control-A Control-n (where n is the session number, 0-n) will switch you to that shell.

Control-A Control-D will detach.

My .screenrc

The only draw back is that the standard .screenrc configuration file is blank which leaves you with no visual indication of whether or not screen is running.

Here is the contents of my ~/.screenrc file which will setup a caption at the bottom of the terminal session which will tell you the host, time, and other session information.

   1: termcapinfo xterm|xterms|xs|rxvt ti@:te@
   2: caption always "%H %c | %x-w%{=}%n-%t%{-}w"
   3: shell -/bin/bash

Labels: ,

Wednesday, April 8, 2009

How to recursively delete files and directories (*.svn) with find and xargs

Every once in a while, I want to delete some files from a set of directories.  Under windows you do a file search, select everything with CTRL-A and delete.  It is every bit as simple under Linux and OS X. 

For example, let's say you want to tar up or merge directories that are checked out of a subversion repository.  If you just tar up the files, you will have extra copies of every single file making the tarball needlessly large.  Not good.  Or maybe you want to delete those .DS_Store files that OS X craps all over your hard drives.

Here's how to do it.  Use the find command to find the .svn directories and pipe the output to the xargs utilities to merge the output into something the rm command can use.  This can be used to quickly delete other files patterns, but be very careful (for obvious reasons):

   1: rm -rf `find . -name "*.svn" | xargs`

Simple.

Labels: ,

Friday, March 13, 2009

Fix: Running screen under Mac OS X clobbers path

I've started using the screen utility under Linux and Mac OS X.  Unfortunately, under Mac OS X, running the screen utility clobbers the path.  The quick fix is to edit ~/.screenrc and add the following code:

   1: shell -/bin/bash
Exit and restart screen.

Labels: ,

Saturday, February 21, 2009

How to force qmake to stop generating an XCode project and generate a gcc makefile instead

Problem: Under OS X, qmake automatically generates an XCode project from a qmake project file.  How do I force it to make a standard gcc makefile?

Unless you have configured Qt when you build it, the default under Mac OS X is to generate an XCode project.  The way to generate a "standard" gcc makefile is to pass the "-spec macxg++" switches on the command line:

   1: qmake -spec macx-g++ 

Additionally, you should place the following into your project file in order to stop it from generating the app_bundle:

   1: mac { 
   2:   CONFIG -= app_bundle 
   3: }

Labels: , ,

Wednesday, January 28, 2009

How do I set ssh session or serial terminal to automatically logout?

There is no auto-logout feature of ssh.  You just have to set the $TMOUT variable in your shell.  To set the terminal to automatically logout after 20 seconds of inactivity, type the following:

   1: $ export TMOUT=20

Your terminal session should be logged out after 20 seconds of inactivity.

Labels: , ,

Wednesday, December 17, 2008

5 Minute Guide to Enabling PHP and Apache under OS X Leopard (10.6)

Apache and PHP are pre-installed by default.  You simply have to enable them.  Turn on web sharing and browse to 127.0.0.1.  You should see the Apache test script. 

Next, edit the apache configuration script to remote the pound sign (#) from the beginning of the line that says, "LoadModule php5_module..."  I use the vim editor, but for those who are command-line challenged, here is a tutorial that uses the graphical editor.

$ sudo vi /etc/apache2/httpd.conf

and edit the php load script line to say:

LoadModule php5_module        libexec/apache2/libphp5.so

Save the file, and restart the webserver:

$ sudo apachectl restart

Next create a test.php file in /Library/WebServer/Documents with the following contents:

<?php phpinfo(); ?>

Browse to http://127.0.0.1/test.php.  You should see the phpinfo output. 

Done!

Labels: ,

Reinstalling OS X from Scratch

It has been almost an entire years since I have switched to using OS X and a MacBook Pro hardware.  With the exception of the retarded one-button mouse and the lack of an CDROM eject button (what the hell were they thinking?), the experience has be overwhelmingly positive for the 8-10 hours a day that I use it. 

My only problem is that my MacBook Pro has slowly developed some odd behaviors, much like that of it's Microsoft cousins: sluggish performance and intermittent crashes thanks to a some software that failed to install correctly.  It was entirely my fault -- I tried to install an upgraded version of subversion that failed, then I added a fink installation, and tried to install an early version of KDE so I could run KDevelop natively.  I failed, and in the process soiled my system drive.

The biggest problem was that the system supplied version of the expat library was overwritten, causing apache, iChat and a number of other software packages to fail on startup.  Worse yet, after upgrading to VMWare Fusion 2, VMs would simply crash without any explanation.  It dawned on me that I might have a few problems while on the road. 

Did I really want to be carting a sick laptop around the world?  No, I didn't.

So last night I decided on the "nuclear option" -- to reinstall OS X on my Mac PowerBook (MBP) from scratch.  It took roughly two hours to install OS X.  Another hour to install the updates, Skype, Firefox, and various other utilities.  I went to bed while it was merging my iTunes library from across the network and awoke to brand new laptop.

Next, it was time to install various utilities.  Here is my basic post installation procedure:

Development Environment Tools:

  • astyle.  C/C++ code formatter.
  • doxygen.  Turns code comments into documentation, complete with call graphs.
  • GraphVis Dot.  Used by doxygen to create call graphs and charts.
  • git.  Rapidly becoming one of the better source code management platforms (subversion is installed by default).
  • Qt.  (the open source version, not the extremely expensive commercial license).
  • XCode.  Apple's IDE for C/C++/Objective-C development.
  • Eclipse.  I still don't like eclipse, but it is becoming too popular to ignore.
  • cppunit.

Utilities:

  • Gnu Privacy Guard.  Encryption and code signing software.
  • wget.  The Swiss army knife of web developers.
  • VMWare Fusion 2.  Software that allows you to run different operating systems inside virtual PCs.

Business:

  • Microsoft Office.

Communications:

  • Skype.  Proprietary VOIP and Instant messaging application
  • Yahoo Messenger.

The system runs much much faster.  

To be continued...

Labels:

Thursday, November 13, 2008

Fail: Synching Palm with iSync and Entourage

Tonight, I spent several hours tonight attempting to synchronize my Palm Pilot Tungsten E2 with Entourage (Microsoft's Mac version of Outlook), in such a way that would allow me to preserve the categories so I could implement GTD.  Unfortunately, I wasted several hours in the attempt and never succeeded 100%.

First of all, much of the information on this on the web is no longer correct.  Microsoft no longer distributes a palm conduit that allows you to synchronize your Palm directly with Entourage.  Instead, you must synchronize  your palm with iSync.

So the process is pretty simple:

  1. Install the palm desktop software and synchronize with your palm.  This will validate that your HotSync utility is working.
  2. Next, run the iSync application and select "Enable Palm OS Synching"  The Apple iSync package contains a Palm conduit.  Got back the Palm HotSync and change the conduit settings to synch with iSync.  Synch and you should see your calendar and tasks populate iCal.  
  3. Finally, set Entourage to synchronize with iCal, etc.,

You are now done, except for one major problem: all of the appointments and tasks on your Palm are dumped into a single category ("Home").  Likewise, if you execute iCal, you will see that it has a new Entourage category.  If you make a change in Entourage, it will show up in iCal under the Entourage calendar.  Changes made to any other categories will not get synchronized with Entourage or the Palm.

In my opinion, that is simply retarded.  Of course, Apple blames Microsoft for not having a conduit of their own for Entourage, completely oblivious to the fact that all Palm data gets funneled into a single calendar category in iCal.

While their may be a workaround that involves plunking $40 down to purchase a third-party condiut, I'm not investing any more time in trying to get this to work.  It's back to Palm Desktop until I can get Outlook running under VMware Fusion to synchronize with the Palm.

Labels: ,

Thursday, March 27, 2008

LD_LIBRARY_PATH in Mac OS X

I keep forgetting, so I thought I would drop a quick blog posting to remind me forever.  For those of you who are moving from Linux to Mac OS, you might be interested:

The equivalent of $LD_LIBRARY_PATH in Linux, is (drum roll please): DYLD_LIBRARY_PATH.

$ export DYLD_LIBRARY_PATH=`pwd`/mydebugpath

And now your application will resolve the shared objects (.dynlib) files at runtime.

For all the glory details you can also man dyld: 

$man dyld

Labels: , ,