Making life easy over flaky links

I tend to work over VPN, which we know can be flaky at times, Since I work on server, I spend a lot of time ssh’ed into hosts. I was getting tired of the lost time having to restart what I was working on every time the VPN dropped (which could be as much as every 15 minutes on a bad day). While I already used screen to handle the lack of terminals (Alas, I am forced to use a Windows laptop to VPN in with), I thought there could be an easier way to do this.

The way I tend to work is that I ssh into a jump server, fire up screen, then ssh into the hosts I need to work on, and fire up screen on those hosts.

Now, this is nice, but it can get a bit tiring to do it all over again. So, I found a tool called autossh which will automatically restart your ssh session if it drops for any reason but a graceful disconnect. (Well, there are others, but this is basically it). Combine this with your ssh-agent, and you can re-attach with easy. I also use keychain to help manage my ssh-agent when I log in.

Now that the connection will come back, I need a way to re-attach to my screen session, or if there is not one, to start one for me. To do
that, I have this is my .bashrc file:

test -x $STY && screen -xR

This will check to make sure that we are not already inside a screen session on the local host (test -x $STY), and if we are not, then either attach to an existing screen session or start a new one (screen -xR)

I have define this function in my .bashrc to spawn a new ssh connection in a separate screen window:

function ss ()
{
  screen -t $1 ssh $*
}

Easy stuff

Add a comment

Welcome back!

Welcome back.

I am restarting this site, and have a few ideas to write about that do not fit on my other sites.

Enjoy!

Add a comment

Search your email!

One of the features that most of the pretty GUI mailers offer you is the ability to search your email. While this is not a feature I use regularly, it is one which when you need it, you really need it. I have used grepmail in the past, but it slow for me (it scans the mail files every time) and the big thing for me is that is only supports mbox files, and I use maildir since I use offlineimap.

I recently found mairix. While I have not been using it long, so far I am very impressed with it. It uses an index to speed up the search process, and it smartly adds only new or changed files to the index. The first indexing run was only a few seconds on my archive of almost 15,000 mail messages. I have it scheduled to update the index every 15 minutes, and I never notice the load this will put on the system.

To integrated mairix with mutt, I wrote a quick little script to search from within (or without) mutt:

#!/bin/bash
#===============================================================================
#
#          FILE:  mailsearch.sh
#
#         USAGE:  ./mailsearch.sh
#
#   DESCRIPTION:  search mail stuff
#
#       OPTIONS:  ---
#  REQUIREMENTS:  ---
#          BUGS:  ---
#         NOTES:  ---
#        AUTHOR:  Don Harper (), duck@duckland.org
#       COMPANY:  Don Harper
#       VERSION:  1.0
#       CREATED:  05/25/2009 07:03:30 PM CST
#      REVISION:  ---
#===============================================================================
	
rm -rf $HOME/Maildir/mfolder
echo "       t::word
              Match word in the To: header.
       c::word
              Match word in the Cc: header.
       f::word
              Match word in the From: header.
       s::word
              Match word in the Subject: header.
       m::word
              Match word in the Message-ID: header.
       b::word
              Match word in the message body.
       d::[start-datespec]--[end-datespec]
              Match messages with Date: headers lying in the specific range.
       z::[low-size]--[high-size]
              Match  messages  whose size lies in the specified range.
       n::word
              Match  word  occurring  as the name of an attachment in the mes-
              sage.  Since attachment names  are  usually  long,  this  option
       F::flags
              Match messages with particular  flag  settings.
              s meaning seen,
              r meaning replied
              f meaning flags
              prefixed by a - to negate its sense.
	
       The a:: search pattern is an abbreviation for tcf:
	
   Match words
       The word argument to the search strings can take various forms.
       ~word
              Match messages not containing the word.
       word1,word2
              This matches if both the words are matched in the specified message part.
       word1/word2
              This matches if either of the words are matched in the specified message part.
       substring=
              Match any word containing substring as a substring
       substring=N
              Match any word containing substring, allowing up to N errors  in
              the  match.   For example, if N is 1, a single error is allowed,
              where an error can be
       *      a missing letter
       *      an extra letter
       *      a different letter.
       ^substring=
              Match any word containing substring as  a  substring,  with  the
              requirement  that  substring  occurs  at  the  beginning  of the
              matched word.
       d::start-end
              Specify both start and end explicitly
"
echo -n "Enter your search string: "
read string
mairix $string
mutt -f=mfolder
rm -rf $HOME/Maildir/mfolder

Then, I bound this to “S'’ from within mutt:

 macro index,pager S "!mailsearch\n" 

This will give me a reminder of the search command, run the search, and then give me the search results in a new mutt session.

Add a comment

C*MUS - A music manager for the terminal

C*mus is an advanced music juke-box for *inx and Window operating systems. It can handle the modern audio file formats: FLAC, Ogg/Vorbis, MP3 , Wav, AAC , MP4, .mod, .s3m, .mpc, mpp, .mp+, .wma, and .wv . It also can deal with many different types of audio output systems: ALSA, libao, ARTS, OSS, Sun, and WaveOut on Windows. The typical features of an electronic juke-box are supported like play lists and random/shuffle play, in addition to easily switching between playing from the library, an artist, or a single album with a simple keystroke.

C*Mus is pretty painless to install from source. The website lists the build dependencies with links. There is no RPM .SPEC file on the web site, but you can use this one.

En-queuing

One of the features I really enjoy and use is the en-queue function. I tend to use this two ways. The first is when I am listening to a song, and want to listen to similar songs, I go find them in my library, and I queue them up with a simple keystroke. A dynamic play-list, if you will. Then, I can simply create a more permanent playlist from this temporary list.

The second way is using the helper program cmus-remote to be able to queue up tracks from a different terminal, or from a script. My podcatcher program (bashpodder) will queue up the podcasts it just downloaded for me, so I can listen to them first thing in the morning.

Keystroke and CLI

C*Mus is developed to be driven via keystrokes. The default mapping is set up to be comfortable for those use are familiar with VI but, it is very easy to remap the keys to make it more comfortable. C*Mus will automatically save the current settings on a clean exit. The default mappings for selecting and updating views, moving through songs forward and backwards in small and large increments, adding to play list and queue lists.

Filters

One of the very powerful features is simple filters. You can set a filter for your 80’s Metal Bands or your Classical music. Many of the common tags can be used for filter on. Things like filename, artist, album, title, genre, discnumber, tracknumber, date (year), duration (seconds), and tag.

Add a comment

Alerting with Remind

Back in my article on Remind, I talked about the simple power of remind to power your scheduling needs.  That is all fine and good, but how to you get it to tell you when you have an event?

In its simplest form, when you run remind <reminder file> from the command line, it will not only display the current day’s reminders, but it will run in the background and wake up to tell you about other reminders on the screen while you work.

This is fine, but what happens if you do not have that termial open in front of you?  Well, I have two ways I approach that issue.

First, when I run under X (yeah, yeah, I know, but I use cli tools under X), I have this added to my .xinitrc:

remind -z -k’xmessage -buttons okay:0 -default okay %s&’ ~/.reminders &

Let’s look at the command line:

  • The -z tells remind to wake up every 5 minutes and reread the .reminders file.
  • The -k tells remind to run a command instead of simply printing the reminder to the screen
  • xmessage -buttons okay:0 -default okay %s& is the secret sauce of this.  This is the command run when there is an alarm.  This command line calls xmessage (which is on pretty much any box with X) to display the alert.  You could use zenity or kmessage, or winpopup, or whatever.  This is what puts the alert in your face when you are not looking at the screen.  The & is needed to make this command non-blocking by putting it in the background.

That all good if you are setting at your computer.  But, what do you do when *gasp* you leave to computer?  This is a little tricker.  For this, my solution needs two things: 1) a computer which is always on and 2) a way to send messages to your cell phone/pager (sms or email).  I have a cron job which checks to make sure remind is running, and restarts it if it is not (I use a hosting provider which does not like long running processes).  The command line is similar to the one for X, but with a difference:

TZ=CDT6CST ~/bin/remind -z -k”echo %s

Add a comment