Stoppt die Vorratsdatenspeicherung! Jetzt klicken &handeln! Willst du auch an der Aktion teilnehmen? Hier findest du alle relevanten Infos und Materialien:
Jump to menu and information about this site.

Monday·24·May·2010

Perfect Team: autossh and GNU Screen //at 13:11 //by abe

from the shell-functions-for-road-warriors dept.

SSH is definitely one of my most often used tools, not only for system administration at work but also on the road with my netbook, an EeePC 701 running Debian Sid.

On the road, it often happens that I have a flaky WLAN or UMTS connection, so I often have to kill (via <Enter>~.) and reconnect my SSH session due to a changed IP address or so.

First step against problems arising from using SSH over unreliable network connections is of course GNU Screen. Second step is use SSH keys and ssh-agent to not needing to type the password on every reconnect.

But it’s still very annoying to kill the SSH connection and call ssh again manually. For luck there is autossh, a wrapper around SSH which regularily checks via two tunnels connect to each other on the remote side if the connection is still alive, and if not, it kills the ssh and starts a new one with the same parameters (i.e. tunnels, port forwardings, commands to call, etc.).

It’s quite obvious that this is perfect to be combined with screen’s -R and -d options (Reattach if a detached screen is around, else start a new screen; detach a currently attached screen), so I found myself very often typing (or fetching it from the commandline history :-):

autossh -t sym.noone.org 'screen -Rd'

-t is necessary to allocate a terminal device on the remote machine which is not done by default if you directly call a command via ssh.

In comparision to OpenSSH, autossh needs the single quotes, because otherwise it would parse -Rd as options to parse to ssh and bail out. That’s not a real problem, but when you’re used to just type ssh -t sym.noone.org screen -Rd without any quotes, you’ll run into this then and when.

Update, 25-May-2010, 14:55: As Carsten Hey points out, autossh also supports the -- option to declare that all following options and parameters must be passed to ssh itself. (End of Update)

Typing that often and mistyping it then and when cries for an shell alias or an shell function. So I came up with the following shell function:

asc() {
    autossh -x -a -t "$@" 'screen -RdU'
}

I used a function instead of an alias in case of autossh will in future regard all parameters given after the command as part of the command as ssh does.

The additional options -x and -a disable X and SSH Agent forwarding which both don’t work if you reattach to an already running screen.

And if you’re using Zsh as I do, you can even add some more format string magic to set the window title more or less to the expanded alias, eh, function:

function asc() {
    # Set the title to something more obvious, e.g. the expanded
    # alias, eh, function
    print -Pn "\e]0;%n@%m: autossh -t $* 'screen -RdU'\a";
    autossh -x -a -t "$@" 'screen -RdU'
}
compdef asc=ssh

Update, 25-May-2010, 14:59: As Hauke points out in a comment, Zsh users should also declare that asc should have the same tab completion as ssh itself. The example above has been updated accordingly. (End of Update)

In the meanwhile on the EeePC I use asc on the commandline more often than ssh itself. And I nearly no more type autossh. (The most common exception here is autossh hostname tail -F /path/to/some/logfile.)

Using that function you can also add common ssh options for tunneling, etc. — I use it most often like this:

asc -D 1080 sym.noone.org

This opens a SOCKS proxy on localhost, port 1080 and that way I can surf via the host I’m connecting to by SSH.

There’s one small drawback though: You didn’t expect that I can just invent some new three letter command without a namespace clash, did you? There is a free game called Advanced Strategic Command whose binary (and Debian package) is named asc, too. If you have that game installed, you can always call it using its full path, e.g. /usr/games/asc on Debian.

P.S.: My whole grml based .zshrc is also available via git at git.noone.org as well as on github.

Filed under: Blogging is futile » English » Computer » Shell »
Tagged as: , , , , , , , , , , , , , , , , , , , , ,
1 comment // show without comments // write a comment //

Thursday·23·April·2009

Screen and Emacsclient: Automatically switching to the Emacs window //at 18:41 //by abe

from the desktop-comfort-in-text-mode dept.

For a very long time, I use mutt with emacsclient as configured editor and a single GNU Emacs instance started from either .screenrc or .Xsession, depending on the system. And I’m very used to switching the virtual desktop or the screen window after starting a mail in mutt.

Since Debian 5.0 Lenny and Emacs 22, Emacs automatically grabs the focus and switches to the right virtual desktop. So after telling mutt recipient and subject of a new e-mail, it invokes emacsclient and immediately the focus has moved to the running Emacs instance. Because I was used to switch one virtual desktop to the right at that point, I often found my self two desktops to the right until I got used to it. :-)

I usually hate applications which grab the focus without being asked. But in this case I basically asked for it. And there’s no delay like with starting up an application which has to read in some database first – think of Liferea or Rhythmbox which take many seconds to minutes to start up, even on my 2.2 GHz dual core ThinkPad.

In the meanwhile I got so used to that automatic desktop switch that I forget to switch the screen window in the second scenario where I use this combination: My screen doesn’t automatically switch to the Emacs window (window 1) after I told mutt recepient and subject in window 2.

Knowing that screen is quite scriptable, I found out that only a very small change is needed to my mutt configuration to get that desktop feature to my everyday screen session. I simply replaced the editor setting in my .muttrc with the following line:

set editor="screen -X select 1;emacsclient"

Now mutt tells screen to switch to window 1 (where Emacs is running) and then tells Emacs to open the appropriate file to edit my new mail.

Update Friday, 2009-04-24, 18:22

Even though Zack surely is right with his comment about the multi-terminal feature of the upcoming GNU Emacs 23, I still have Etch (and therefore GNU Emacs 21) on the server where I have my screen session.

So the next step was to switch back to the mutt window (window 2) after I’m finished with editing the mail. Since mutt gives the the file to edit as argument to the contents of $editor, simply adding ;screen -X select 2 at the end of $editor doesn’t suffice.

So I wrote a small shell script (named ~/.mutt/editor.sh) as wrapper which calls all the commands and passes the parameters to the right command:

#!/bin/sh

screen -X select 1
emacsclient -a ~/.mutt/alteditor.sh "$@"
screen -X select 2

Of course, $editor is now set to that script:

set editor="/home/abe/.mutt/editor.sh"

Emacsclient of GNU Emacs 21 already supports the -a option to call another editor in case of not being able to connect to a running Emacs instance. Since I don’t want to switch to another screen window in that case, I wrote a second shell script (named ~/.mutt/alteditor.sh) which switches back to the mutt window and then calls GNU Zile, my preferred low-end emacs clone:

#!/bin/sh

screen -X select 2
zile "$@"
screen -X select 1

I love it!

Filed under: Blogging is futile » English » Computer » Shell »
Tagged as: , , , , , , , , , , , , , ,
1 comment // show without comments // write a comment //

Sunday·20·May·2007

autossh vs TCP resetter //at 00:49 //by abe

from the lick-my-ass-script-kiddie dept.

LUG-Camp 2007 in Interlaken is nearly over, and I’m reading my mail as usual using ssh, screen and mutt on the server. But the ssh connection resets every few minutes. According to the LUSC people (who are running the gateway) some script kiddie is running a TCP resetter somewhere in the network.

I remembered that I read about autossh in the Debian package list once a while and that it sounded cool but I had no use for it yet. Until now.

I’m writing this over the same crashing ssh connection and I’m typing without taking big notice of the quite often occurring connection resets:

autossh noone.org -t 'screen -rd'

It just works. :-)

Filed under: Blogging is futile » English » Computer » Shell »
Tagged as: , , , , , , , ,
1 comment // show without comments // write a comment //

Friday·20·October·2006

Nice Shell Bloomer //at 16:39 //by abe

from the works-for-me dept.

While looking for users which still have “.” in their path, I found the following nice bloomer:

PATH=``$PATH:.:$HOME/bin''

It’s obvious what the user tried to do. But why the fuck does this (more or less man or info page alike) quoting syntax work?

It took me a moment to realise that this kind of “quoting” works in nearly all Unix shells: The two backquotes as well as the two single quotes become an empty string and are therefor completely useless in this case.

The user probably read some uglily localized man or info page (like the German ones in Debian Sarge) and did some copy and paste to his .bashrc. And since it “worked” he didn’t see any reason to change it again.

Filed under: Blogging is futile » English » Computer » Shell »
Tagged as: , , , , , , , , , , ,
0 comments // show without comments // write a comment //

Thursday·02·March·2006

Shell Efficiency Talk at DaLUG today //at 02:29 //by abe

from the testbed dept.

I just uploaded the slides for my shell efficiency talk at the Darmstadt Linux User Group (DaLUG) today at 18:30 CEST at the Technical University of Darmstadt. (The talk will be held in German.)

I will also hold a workshop about the same subject on the 29th of October 2005 at Linux-Info-Tag Dresden. (Will also be held in German.)

Filed under: Blogging is futile » English » Computer » Shell »
Tagged as: , , , , , , , , , , ,
0 comments // show without comments // write a comment //

Probably moving from tcsh to zsh. Bash sucks. //at 02:29 //by abe

from the habits dept.

The grml-T-Shirt, Alfie was wearing at the Debian QA Meeting in Darmstadt this weekend reminded me, that I wanted to download a grml-ISO. While looking for the ISO I found a link to the grml zsh Reference Card. Beneath the links to the reference card there were a pointer to zsh-lovers, “a small project which tries to collect tips, tricks and examples for the Z shell.”.

There were a lot of nice tricks mentioned, e.g. redirection to multiple files. So I spawned a zsh and checked for the main feature, which keeps me using tcsh instead of bash: History Tab Completion. And see there: zsh does History Tab Completion. And even nicer: Completion results don’t create a new prompt, but just show up (and vanish again with e.g. ^C) beneath the prompt while the prompt only moves (up) if there’s not enough space for all the possible completions. Some kind of meta-cool is the set of configuration variables starting with CSH_JUNKIE_. Guess, I am such a (t)csh junkie. ;-)

And global aliases seem also a very fine (but also very dangerous) feature. Think of cd ... just doing what you want it to, namely cd ../... As well as the advanced history handling which includes incremental sharing with multiple simultaneous shells. Or the spelling corrections based on keyboard layout.

On the other hand, zsh offers everything from bash I missed in tcsh: ^R and usable loops (mostly while (true); do ...) on the command line. The only thing none of the three shells can is Mind Tab Completion. ;-)

The zsh page from Adam Spiers seems to be good source for informations about the zsh. Another nice collection of zsh tips (which often also work in other shells) was in the links section of the grml zsh page.

Funnily several people tried to convince me to use zsh before, but they just didn’t use the right arguments. :-) So it looks as if I found the right arguments by myself and should really give zsh a try after 10 years of tcsh. Although I already found something less amusing in zsh: echo '\n' and echo "\t" behave both very strange, but I still hope, I find the switch to turn it off…

But my upcoming shell efficiency talk will definitely not only feature bash and tcsh but also zsh.

Now playing: R.E.M. — Losing my religion

Filed under: Blogging is futile » English » Computer » Shell »
Tagged as: , , , , ,
1 comment // show without comments // write a comment //

Next planned shell efficiency talks //at 02:28 //by abe

from the calendar dept.

Today is the deadline for proposing talks for this year’s LinuxTag (3rd to 6th of May, Wiesbaden, Germany) and last week was the deadline for talk proposals for this year’s Chemnitzer Linux-Tage (CLT, 4th and 5th of March 2006, Chemnitz, Germany). For both events I submitted my already at other events held Shell Efficiency talk. For LinuxTag I marked the proposal as “German preferred, English possible”, so if they ask for the English version, I’ll offer the slides in English, too, of course. I’ll probably also build a DocBook version of the talk, since LinuxTag prefers the DocBook format.

But even if these both talk proposals are not accepted, I’ll be on both events together with the rest of the Symlink crew and have fun! ;-)

Additionally I will hold the talk a few days before CLT on Thursday the 2nd of March 2006 at the New Thinking Store in Berlin-Mitte, Tucholskystraße 48 at 19:30 (which is unfortunately in parallel to this year’s German Perl Workshop from 1st to 3rd of March 2006 in Bochum). The entrance to the talk is free. (Thanks to Sven Guckes for suggesting this talk and bringing me in contact with New Thinking.)

Now Playing: Jethro Tull — Orion

Filed under: Blogging is futile » English » Computer » Shell »
Tagged as: , , , , , , , , , , ,
0 comments // show without comments // write a comment //

Tag Cloud

2CV, Automobiles, Berlin, bijou, Blogging, Blosxom, Blosxom Plugin, Browser, BSD, CDU, Chemnitz, Citroën, CLT, Conkeror, CX, Debian, Doofe Parteien, eBay, EeePC, Emacs, Epiphany, Etch, ETH Zürich, Events, Firefox, Fläsch, FreeBSD, Galeon, Gecko, GNOME, Google, GPL, Hacks, Hardware, Heise, identi.ca, IRC, Jabber, JavaShit, Kazehakase, Lenny, Linux, LinuxTag, LUGS, Lynx, maol, Meme, Microsoft, Mozilla, Music, mutt, München, nemo, Nokia, Open Source, Opera, Pentium I, Perl, Planet Debian, Planet Symlink, Quiz, Rant, ratpoison, Religion, RIP, Sarcasm, Sarge, Schweiz, screen, Shell, Sid, Spam, Stöckchen, SuSE, Symlink, Symlink-Artikel, Tagging, Talk, taz, Text Mode, ThinkPad, Ubuntu, USA, USB, VCFe, Ventilator, Vintage, Wahlen, Wikipedia, Windows, WML, Woody, WTF, X, zsh, Zürich, ÖPNV

Calendar

 2010 →
Months
SepOct Nov Dec
 September →
Mo Tu We Th Fr Sa Su
    2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30      

Tattletale Statistics

Blog postings by posting time
Blog posting times this month



Search


Advanced Search


Categories


Recent Postings

8 most recent of 8 postings total shown.


Recent Comments


AideRSS Top 10


Hackergotchi of Axel Beckert

About...

This is the blog or weblog of Axel Stefan Beckert (aka abe or XTaran) who thought, he would never start blogging... (He also once thought, that there is no reason to switch to this new ugly Netscape thing because Mosaïc works fine. That was about 1996.) Well, times change...

He was born 1975 at Villingen-Schwenningen, made his Abitur at Schwäbisch Hall, studied Computer Science with minor Biology at University of Saarland at Saarbrücken (Germany) and now lives in Zürich (Switzerland), working at the IT Support Group (ISG) of the Departement of Physics at ETH Zurich.

Links to internal pages are orange, links to related pages are blue, links to external resources are green and links to Wikipedia articles, Internet Movie Database (IMDb) entries or similar resources are bordeaux. Times are CET respective CEST (which means GMT +0100 respective +0200).


RSS Feeds


Identity Archipelago


Picture Gallery


Button Futility

Valid XHTML Valid CSS
Valid RSS Any Browser
PageRanker.org PageRanker.org
Free Google Page Rank Checker (that either doesn't work at the moment or you don't see images in general, if you see this. ;-) GeoURL
This content is licensed under a Creative Commons License (SA 3.0 DE). Some rights reserved. Hacker Emblem
Get Mozilla Firefox! Powered by Linux!
Typed with GNU Emacs Listed at Tux Mobil
XFN Friendly Button Maker
Weblog counter Blogstats

Blogroll

Blog or not?


People I know personally


Other blogs I like or read


Independent News


Interesting Planets


Web comics I like and read

Stalled Web comics I liked


Blogging Software

Blosxom Plugins I use

Bedside Reading

Just read

  • Bastian Sick: Der Dativ ist dem Genitiv sein Tod (Teile 1-3)
  • Neil Gaiman and Terry Pratchett: Good Omens (borrowed from Ermel)

Currently Reading

  • Douglas R. Hofstadter: Gödel, Escher, Bach
  • Neil Gaiman: Keine Panik (borrowed from Ermel)

Yet to read

  • Neil Stephenson: Cryptonomicon (borrowed from Ermel)

Always a good snack

  • Wolfgang Stoffels: Lokomotivbau und Dampftechnik (borrowed from Ermel)
  • Beverly Cole: Trains — The Early Years (getty images)

Postponed

Technorati