Mike Neir's Page[ignignokt][err]
Mike loves the feeling when he listens to a song he's heard a hundred times before and hears something new. (709 days ago)
Viewing 1 posts tagged with 'bash'
(Oldest First :: Newest First)
Show related: del.icio.us links, tags

Smart ssh'ing using screen

Wednesday, November 02 2005, 12:41 AM

This has probably been done before, but I decided to set up a bash script tonight that would overload the ssh command and manage ssh connections using screen. I set it up so that when a detached screen to the host you're connecting to is present, it would reattach that screen session instead of making a new one. If there weren't any detached sessions, it starts up a new screen session by connecting to the host. I also made it name the screens in a somewhat intelligent manner. If the host you're connecting to is specified by an IP address, it'll attempt a reverse lookup to provide a more beneficial name than the IP. If the reverse lookup fails, it'll just use the IP. If you're connecting to a host based on a full or partial hostname, it'll just use that as the screen name. I also made another command to shortcut searching for screens - lsscr. If it's run with no parameters, it lists all screen sessions. If it is run with a parameter, it'll take that parameter as a search string and show screen sessions matching that search string. And since I dig open source, I post my work here for all to pilfer.

[EDITx2] I've updated the functions a few times, and instead of reformatting HTML each time, I'm just going to post it in the wiki. Enjoy. [/EDITx2]

This code should be placed in your user's .bashrc file (or the server-wide copy, if you prefer) for this to work right.

Tags:

Related Tags

              


RSS Feed | Comments RSS Feed | Valid HTML 4.01 | Valid CSS
Memcache: Hits: 30 Misses: 0 Updates: 0 Deletes: 0 LocalHits: 1 Time: 0.0075
MySQL: Selects: 2 Inserts: 0 Updates: 0 Deletes: 0 Time: 0.0004
Page Render Time: 0.1624 seconds