Reading Time: 5 minutes
As a lot of readers already know, from comments and discussions on other forums, I recently made the switch from PC to Mac for my main personal computer. This wasn’t some sort of Microsoft-hating frenzy, but rather a case where I had more compelling reasons to use a Mac at home (Apple TV, iTunes, wife’s Mac, etc.) than I did to stick with the PC (games). I still have the PC for when I get the gaming urge, but since most of my time these days is spent studying, gaming has taken a back burner for the foreseeable future.
I won’t bother you with my initial reactions to the Mac as they’ve been mostly positive and probably not entirely different than many other people’s experiences. What I will say, though, is that as a long time user of various flavors of Unix, it’s nice to be operating on a platform that is Unix based again. Specifically, it’s nice to not have to download bolt-on software in order to be able to use SSH, Finger, TFTP, etc.
One of the tools that I have used extensively in the past is GNU Screen. For those unfamiliar with the program, you can check out a brief overview over at Wikipedia: http://en.wikipedia.org/wiki/GNU_Screen , or at the GNU Screen website here: http://www.gnu.org/software/screen/ .
Despite using Screen since I was first introduced to it back around 1990 or so, if I recall correctly, I’ve only ever used it really for one thing: connecting from a Unix Machine to something using the serial port or a modem. Even the modem bit I didn’t use all the time as I tended to favor Minicom. So, when a couple of friends suggested that I use Screen for solving a problem I was having, it made sense.
As part of my Cisco lab I have some fourteen different devices that I need to access at any one time. I have all of those devices set up to my main terminal server (3945 which is also my main a‑lot-of-other-things as well) using reverse telnet. In this way I can do a lot of things, but typically I would SSH to the terminal server, connect to a host by name, then use Ctrl-Shift‑6 x to get back to the terminal server and do the same thing again for another host.
This is all made possible using an Async card:
NAME: "High Speed Wan Interface card with 16 RS232 async ports(HWIC-16A) on Slot 0 SubSlot 3", DESCR: "High Speed Wan Interface card with 16 RS232 async ports(HWIC-16A)"
With a pertinent configuration like so:
interface Loopback0
ip address 172.16.0.1 255.255.255.0
ip host s2 2054 172.16.0.1
ip host s1 2053 172.16.0.1
ip host s4 2056 172.16.0.1
ip host s3 2055 172.16.0.1
ip host r5 2063 172.16.0.1
ip host r2 2060 172.16.0.1
ip host r6 2064 172.16.0.1
ip host r4 2062 172.16.0.1
ip host r3 2061 172.16.0.1
ip host r1 2059 172.16.0.1
ip host r8 2066 172.16.0.1
ip host r7 2065 172.16.0.1
ip host ASA 2051 172.16.0.1
ip host AP1 2052 172.16.0.1
ip host bb2 2057 172.16.0.1
ip host bb1 2058 172.16.0.1
line 0/3/0 0/3/15
session-timeout 120
no exec
transport input telnet
Still, opening fourteen hosts can get tedious, as you might imagine.
What this configuration also allows for, however, that I had only been using occasionally is logging in to any device by opening a telnet connection to the port. So, I can either telnet to the parent device’s IP address (in this case it’s 10.7.68.221) or to the loopback address (if I have routing) and adding on the port number like so:
telnet 172.16.0.1 2056
which, as we see from above, would take me to the device labeled “s4”. That’s all good, but still requires me to open each telnet session by hand, right? Not necessarily: enter Screen and the magic of configuration files.
I have two configuration files for Screen: one is a .screenrc file which sits in my home directory as is standard on Unix systems. Note that I could also put this in my /etc directory and change the name if I wanted a system-wide default for all users. The other file is a custom one that I only use when I’m doing lab-work, and I call that one screen.ccie.
If I want to open just Screen by itself, from a terminal (I use iTerm2) I just type “screen –A” which opens up Screen with all possible emulations enabled (just in case). If I want to open my ccie lab configuration I type “Screen –Ac screen.ccie” to reference the startup file. I also use “screen –A /dev/tty.KeySpansomething” to use my USB/Serial adapter if I’m at the console somewhere.
Below you’ll find the screen.ccie file, with comments, as well as a screen shot of what it looks like in action. I didn’t include the .screenrc file because it is identical, except for the last section that opens up all of the different telnet sessions. I’m sure there are a lot of ways to do this, some better than others, and infinite combinations of colors, stats, etc. that can be configured, but this is what I have for now.
# SomeClown's .screenrc file. Cribbed from a lot of places. # Credit to both @IPv6Freely and @jay25f # Next and Previous tabs shortcuts bindkey "^e" next # Next bindkey "^w" prev # Previous # Various options escape ^Zz # Control-A is needed elsewhere nethack on # Just 'cuz maptimeout 5 # Fixes Vi vbell off # Pavlov startup_message off # Meh defscrollback 30000 # Lots o' logging room autodetach on # Go away, come back. shelltitle "" # Status at bottom of screen; tabs, etc. The code's a FusterCluck, but looks nice hardstatus alwayslastline "%-Lw%{= BW}%50>%n%f* %t%{-}%+Lw%< %=%D %M %d %c" hardstatus string '%{= kK}%-Lw%{= KW}%50>%n%f %t%{= kK}%+Lw%< %{=kG}%-= %d%M %c:%s%{-}' # Specific for CCIE Lab. Standard .screenrc file doesn't include text below # Create named tabs for each device screen -t Stuff 0 # General screen -t R1 1 screen -t R2 2 screen -t R3 3 screen -t R4 4 screen -t R5 5 screen -t R6 6 screen -t R7 7 screen -t R8 8 screen -t S1 9 screen -t S2 10 screen -t S3 11 screen -t S4 12 # For each tab above, do stuff at R1 stuff " echo 'Starting some shite...' && sleep 10 && telnet 10.7.68.221 2059 \015" at R2 stuff " echo 'Starting some shite...' && sleep 10 && telnet 10.7.68.221 2060 \015" at R3 stuff " echo 'Starting some shite...' && sleep 10 && telnet 10.7.68.221 2061 \015" at R4 stuff " echo 'Starting some shite...' && sleep 10 && telnet 10.7.68.221 2062 \015" at R5 stuff " echo 'Starting some shite...' && sleep 10 && telnet 10.7.68.221 2063 \015" at R6 stuff " echo 'Starting some shite...' && sleep 10 && telnet 10.7.68.221 2064 \015" at R7 stuff " echo 'Starting some shite...' && sleep 10 && telnet 10.7.68.221 2065 \015" at R8 stuff " echo 'Starting some shite...' && sleep 10 && telnet 10.7.68.221 2066 \015" at S1 stuff " echo 'Starting some shite...' && sleep 10 && telnet 10.7.68.221 2053 \015" at S2 stuff " echo 'Starting some shite...' && sleep 10 && telnet 10.7.68.221 2054 \015" at S3 stuff " echo 'Starting some shite...' && sleep 10 && telnet 10.7.68.221 2055 \015" at S4 stuff " echo 'Starting some shite...' && sleep 10 && telnet 10.7.68.221 2056 \015"