Thursday, September 13, 2012

A Serial Console on OSX

A lot of times I find myself needing to recover passwords on old routers and switches that the world has forgotten about (along with their passwords, hence the password recovery).  It was easy in my PC days to simply fire up HyperTerm and go, and most Linux distributions still come with Minicom, if you know where to look.  But OSX is different.  There are 3rd party apps available, and I used zTerm for a while, but then I found you could simply use the OSX terminal app and a couple of quick commands to get a very capable, tabbed environment for mixing console and SSH access to a bunch of devices.  Perfect!

So you will need to start with a USB-to-Serial adapter that's supported by OSX.  I've had lots of success with PL2303 variants, so look for that chip in your adapter of choice.  Once you have it, plug it in and run the following command and watch the output:


bigmac:~ greg$ ls -l /dev/tty.*
crw-rw-rw-  1 root  wheel   18,   2 Sep 13 06:03 /dev/tty.Bluetooth-Modem
crw-rw-rw-  1 root  wheel   18,   0 Sep 13 06:03 /dev/tty.Bluetooth-PDA-Sync
crw-rw-rw-  1 root  wheel   18,   4 Sep 13 09:28 /dev/tty.PL2303-00001004

Now unplug the adapter and repeat:

bigmac:~ greg$ ls -l /dev/tty.*
crw-rw-rw-  1 root  wheel   18,   2 Sep 13 06:03 /dev/tty.Bluetooth-Modem
crw-rw-rw-  1 root  wheel   18,   0 Sep 13 06:03 /dev/tty.Bluetooth-PDA-Sync

Notice the entry that went away?  That's my adapter's device name.  In my case the naming was pretty obvious, but that may not always be the case.

Anyway, now that I know the name of my device, I can plug it back in and use the screen utility to open up a console session:

gbensimon-sslvpn-nc:~ greg$ screen /dev/tty.PL2303-00001004 9600

This will open a session at 9600 bps via my USB-to-Serial adapter.  Once engaged, A-? will bring up a useful help screen:

                       Screen key bindings, page 1 of 1.

                       Command key:  ^A   Literal ^A:  a

  break       ^B b         license     ,            reset       Z         
  clear       C            lockscreen  ^X x         screen      ^C c      
  colon       :            log         H            select      '         
  copy        ^[ [         meta        a            silence     _         
  detach      ^D d         monitor     M            split       S         
  digraph     ^V           next        ^@ ^N sp n   suspend     ^Z z      
  displays    *            number      N            time        ^T t      
  dumptermcap .            only        Q            title       A         
  fit         F            other       ^A           vbell       ^G        
  flow        ^F f         pow_break   B            version     v         
  focus       ^I           pow_detach  D            width       W         
  hardcopy    h            prev        ^H ^P p ^?   windows     ^W w      
  help        ?            quit        ^\           wrap        ^R r      
  history     { }          readbuf     <            writebuf    >         
  info        i            redisplay   ^L l         xoff        ^S s      
  kill        ^K k         remove      X            xon         ^Q q      
  lastmsg     ^M m         removebuf   =         

^]  paste .
"   windowlist -b
-   select -
0   select 0
1   select 1
2   select 2
3   select 3
4   select 4
5   select 5
6   select 6
7   select 7
8   select 8
9   select 9
]   paste .


                        [Press Space or Return to end.]

You'll see it's pretty full-featured.

I've been using this since the Tiger (10.4) days.  I had some issues with Snow Leopard (10.6) and 64-bit support, but updated drivers seem to have resolved the problems.  I'm currently on Mountain Lion (10.8), and it's still working great.

Tuesday, September 04, 2012

Safari 6 and Mountain Lion Hell

Once upon a time, OSX was rock-solid.  You could upgrade from one release to the next on Day 1 and have supreme confidence that things were going to "just work" as they had in the past.  Lion broke that, and Mountain Lion seems to have added more problems without fixing what Lion broke.  This time it's Safari.

Once I completed my ML upgrade and restarted, I opened up Safari as I always do.  My standard start page (http://www.apple.com/startpage/) came up fine.  Then I tried to browse to GMail.  The progress bar quickly moved to about 25% complete, but then it just hung, and the page was never rendered.  Thinking it was a GMail issue, I tried CNN...and Facebook...and my company SSL portal...all the same.  Meanwhile I had the Pinwheel of Death spinning in my browser while the Safari Web Content process spiked to near 100%.  The Console app showed nothing relating to Safari.

I reset Safari and cleared everything I could check -- no change.  I disabled Java, JavaScript, and all plugins from the Safari preferences -- no change.  So I tried some Google-Fu, looking for terms related to Safari, Mountain Lion, "Web Content", and CPU looking for ideas -- nothing.  So I bailed on Safari and started using Chrome in the interim (which has been nice).

I didn't want to give up, so I tried again today.  I came a bit closer when I found this article on the Apple Support Community.  The process didn't solve my problem, but I keyed on the following quote:

Flash CONTENT itself was not sucking up the CPU, but merely the Flash PLUGIN BEING INSTALLED was what sucked up the CPU time.

So I went General Sherman on my plugins.  Typically you find plugins in one of two places:

/Library/Internet Plugins/
~/Library/Internet Plugins/

Granted, the second location isn't a single location (every user potentially has his own plugins), but you get the idea.  So I closed all my browsers, opened a terminal session and ran the following three commands:

sudo rm -rf /Library/Internet Plugins/*
cd ~
rm -rf Library/Internet Plugins/*

I restarted my laptop, opened Safari, and viola!  Safari opened every page I navigated to.  Of course it complained of missing plugins, but I have installed the latest releases of Flash and Java 6 so far without issue.  In order to get Java 6 running in Safari again, I also needed this command:

sudo ln -s /System/Library/Java/Support/CoreDeploy.bundle/Contents/JavaAppletPlugin.plugin /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin

Just make sure you get the whole command on a single line (no carriage returns).