blog/templates/month_archive.htm - header
31.05.2006 23:18:49

NanoBlogger und Umlaute...

Wie jeder sehen kann, benutze ich für mein Blog ein sehr geniales Bash-Tool namens NanoBlogger. Das Tool ist nicht besonders komfortabel, wie jeder zugeben wird, der es benutzt. Jedoch kommt es ohne Datenbank aus, man kann den Editor seiner Wahl nutzen (natürlich vim) und dank einer geschickten Template-Struktur kann man es fast beliebig im Aussehen verändern.

Das Problem

Was aber wohl für einige deutschsprachige Nutzer ein Problem zu sein scheint, ist das Thema Umlaute. Zumindestens haben sich in den letzten Woche zwei oder drei User auf meine Seite verirrt, die scheinbar rausfinden wollten, wie sie ihre Umlaute korrekt dargestellt bekommen. Daher hier ein paar kleine Infos zu dem Thema, wie ich sie verstanden habe. :)

Nanoblogger ist in der Standard-Konfiguration auf UTF-8-Inhalte eingestellt. Dies kann man an zwei Stellen sehen. Zum einen am Header der erstellten HTML-Dateien (index.html):

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
  "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta name="generator" content=
"HTML Tidy for MkLinux (vers 12 April 2005), see www.w3.org" />
<meta http-equiv="Content-Type" content=
"application/xhtml+xml; charset=utf-8" />
<meta name="generator" content="NanoBlogger 3.2" />
<meta name="robots" content="all" />
<meta name="revisit-after" content="31 days" />
<title>My Weblog</title>

zum anderen an den folgenden Zeilen aus der Konfiguration, die standardmässig erstellt wird blog.conf:

...
BLOG_CHARSET="utf-8"
...
TIDY_HTML_ARGS="-asxhtml -n -utf8"
TIDY_XML_ARGS="-xml -n -utf8 -wrap 0"
...

Dass heisst, wenn man seine Einträge im Editor speichert, dann muss man dafür sorgen, dass die Datei UTF-8-kodiert gespeichert wird. Standardmässig sind nun allerdings die meisten Linux-Distributionen auf Latin-1 eingestellt, was dazu führt, dass die Umlaute im Blog nicht korrekt dargestellt werden.

Lösung 1: Dateien UTF-8-kodiert speichern

Wie man die verschiedenen Editoren dazu bringt, die Datei als UTF-8 zu speichern, kann ich hier natürlich nicht zusammenfassen. Aber für meinen Lieblingseditor vim ist die Sache eigentlich relativ einfach. Beim Speichern der Datei nicht wie sonst einfach :w tippen, sondern das folgende nutzen:

:w ++enc=utf-8

Dies muss man allerdings jedesmal beim Speichern berücksichtigen und nicht vergessen. Sonst landet schon wieder Datenmüll im Blog.

Weitere Hinweise in der vim-Hilfe mit :help ++enc.

Lösung 2: Nanoblogger auf Latin-1 umstellen

Alternativ kann man natürlich Nanoblogger auf Latin-1 umstellen. Dann kann man seinen Editor wieder ganz normal benutzen und braucht sich keine Gedanken mehr um die Kodierung der Dateien machen.

Hierzu muss man nur die oben bereits gezeigten Zeilen wie folgt modifizieren:

...
BLOG_CHARSET="iso-8859-1"
...
TIDY_HTML_ARGS="--doctype transitional -asxhtml -n -latin1"
TIDY_XML_ARGS="-xml -latin1 -n -wrap 0"
...

Wichtig ist es, die Konfigurationszeilen für Tidy nicht zu vergessen. Ansonsten "korrigiert" Tidy das gewünschte Encoding in den HTML-Dateien wieder auf UTF-8 und man sieht wieder keine Umlaute.

Nach dieser Korrektur und reparsen der bisherigen Blogeinträge mit

nb -b PATH -u all

sollten nun alle Umlaute korrekt dargestellt werden. Ab jetzt muss man beim Speichern der Dateien nichts mehr berücksichtigen.

Ich hoffe, dieser Artikel wird dem einen oder anderen helfen. Für Korrekturen und Kommentare bin ich immer offen und würde mich sogar speziell darüber freuen.


Erstellt von Jerri | Permalink | Kategorie: homepage, konsole | Kommentare
27.05.2006 10:30:56

Verschiedenes...

Heute mal keine Consolen-Tips, sondern einfach ein paar Links, die ich im Netz gefunden habe. Z.B. diesen hier:

Classic kids theme tunes

Mach dich auf eine Zeitreise in deine Kindheit. Obwohl die verlinkten Titelmusiken auf Englisch sind, kann man doch die meisten wiedererkennen. Wer hat sie nicht alle damals im Fernsehen gesehen? Einiges sogar dabei, an das man sich garnicht mehr erinnern konnte. Oder wer kann sich erinnern, eine Fernsehserie namens "StreetHawk" gesehen zu haben? Ich nicht mehr. Aber die Titel-Musik kannte ich noch! :)

Oder was lustiges für die Homepage oder für Forums-Beiträge (wobei ich sowas lieber nicht in Forums-Beiträgen sehen würde. :) Den Text kann man beliebigen wählen. Einfach auf das Bild klicken um eigene Nachrichten zu erstellen!

Ninja!

Und wer sich schonmal gefragt hat, was das Web 2.0 eigentlich ist, dem sei die folgende Seite ans Herz gelegt:

Web2.0Slides | Web2.0 Slideshow

Die Website sammelt alle sog. Web 2.0-Applikationen im Netz und stellt sie dann als eine Slideshow vor. D.h. Play klicken, zurücklehnen und Webseite für Webseite genießen. Wer weiss, ob man nicht einen neuen Favoriten im Netz findet. :)

Und zu guter Letzt noch eine Website für Grafikbegeisterte:

Fiery Darts Your Source for Unique Adobe Photoshop Tutorials

Sehr schön gemachte Tutorials die einem Ideen für eigene Kreationen am PC geben. Ich denke, ich muss das Design meiner Homepage auch nochmal überarbeiten. Vielleicht etwas mit noch mehr Glanz und Bling Bling... :)

Einen hab ich jetzt doch noch. Ich bin bekennender Homestarrunner.com-Fan (eigentlich insbesondere Fan der Strongbad-Emails). Hintergründe und Zusammenfassungen zu dieser wirklich witzigen Website kann man unter folgendem Wiki finden:

Main Page - Homestar Runner Wiki

Viel Spass beim Rumstöbern...


Erstellt von Jerri | Permalink | Kategorie: interessant | Kommentare
23.05.2006 14:16:37

Noch eine vim7-Änderung bei Debian...

Da haben die Debian-Paketverwalter mal richtig aufgeräumt bei der vim7-Installation. Neben der Änderung von gestern, die ich offensichtlich auch umgehen hätte können, indem ich das Paket vim-full installiert hätte, welches den Default nano wieder überschreibt, ist vim nun auf der Kommando-Zeile so konfiguriert, dass bei Start von vim als vi ein zu vi kompatibles vim gestartet wird.

Dies wird dadurch bewerkstelligt, dass vim beim Aufruf als vi auch die virc-Dateien zusätzlich liest. Bei Debian existiert nun per Default eine Datei /etc/vim/virc mit dem folgenden Inhalt:

" Vim configuration file, in effect when invoked as "vi". The aim of this
" configuration file is to provide a Vim environment as compatible with the
" original vi as possible. Note that ~/.vimrc configuration files as other
" configuration files in the runtimepath are still sourced.
" When Vim is invoked differently ("vim", "view", "evim", ...) this file is
" _not_ sourced; /etc/vim/vimrc and/or /etc/vim/gvimrc are.

set compatible

" vim: set ft=vim:

Indem man die Zeile set compatible in dieser Datei auskommentiert (mit ") erhält man mit vi wieder einen ganz normalen voll funktionsfähigen vim.

Bin gespannt, was ich noch alles ändern muss, damit ich mit den neuen vim7-Paketen von Debian wieder auf dem alten Stand bin. :-)


Erstellt von Jerri | Permalink | Kategorie: linux, konsole, vim | Kommentare
22.05.2006 12:39:10

vim not default anymore on debian...

It seems the debian community prefers nano to vim. With the newest unstable debian installed if you do for example cvs commit you get the nano-Editor to edit your commit-message instead of vi. This happens allthough $EDITOR and $CVSEDITOR are not set.

If you don't like nano and want your beloved vi back again do the following as root:

$ update-alternatives --config editor

Answer the following question with your preferred editor.

This sets the default-editor for the whole system. (There are more default programs you can set with this debian command. Take a look at man update-alternatives)

If you want to set the default-editor for your user only you alternatively can set the $EDITOR variable in your shell configuration (.bashrc for bash):

export EDITOR=/usr/bin/vim

Erstellt von Jerri | Permalink | Kategorie: linux, konsole, vim | Kommentare
17.05.2006 23:28:54

Ein paar VIM-Links...

Es ist immer wieder erstaunlich, wie schnell und einfach man mit vim Texte editieren kann, wenn man sich erstmal auf das Abenteuer eingelassen hat, vim tatsächlich zu lernen. Einen Klassiker von Bram Moolenaar selber (dem Programmierer von vim), kann man hier finden:

Vim: Seven habits of effective text editing

Warum ich so gerne vim benutze, liegt daran, dass ich ungern zur Maus greife. Es ist tatsächlich so, dass es Applikationen gibt, bei denen eine Maus einfach unabdingbar ist. Programmieren in einem Editor ist meiner Meinung nach aber nicht so ein Fall! Warum dann vim und nicht emacs? Nun, zum einen, weil ich finde, dass emacs viel zu gross ist fuer einen einfachen Editor. Zum anderen, weil die Bedienung von emacs in Finger-Streck-Übungen ausartet. Das Prinzip der zwei Bearbeitungsmodi in vim (und ursprünglich vi) macht es möglich, die meisten Befehle mit einfachen Tastenklicks zu erreichen. Kein übermässiges Drücken der CTRL und ALT Tasten ist nötig. Und selbst zum Navigieren im Dokument muss man nie die Haupttasten der Tastatur verlassen (keine Cursor-Keys nötig!)

Hilfreich, und von mir schonmal gepostet, aber weil sie eben so hilfreich sind, hier nochmal:

Graphical vi/vim Cheat Sheet and Tutorial

Wer schon einigermassen mit vim gearbeitet hat, hat vielleicht noch die eine oder andere Frage offen. Hier kann die (sehr ausführlicher FAQ) helfen:

Vim online doc: Vim FAQ

Und warum ich diesen Artikel heute wieder schreibe liegt insbesondere daran, dass ich das folgende Skript gefunden habe: Es ermöglicht es einem beim Editieren von XML und HTML-Dateien, das letzte nicht geschlossene Tag mit einer einzigen Tastenkombination zu schliessen:

closetag.vim - Functions and mappings to close open HTML/XML tags : vim online

Und da es meistens hilft, wenn ich Sachen einfach mal verspreche, und dann halten muss. Ich bin gerade wieder im Begriff, einen neuen Artikel zu schreiben. Diesmal zum Thema "Wie vermeide ich die Nutzung der Maus". In der Arbeit benutze ich die Maus inzwischen wirklich nur noch, wenn ich im Firefox unbedingt surfen muss. Ansonsten kann ich ausschliesslich mit meiner Happy Hackers-Tastatur arbeiten. Welche Tools ich nutze, und welche Tips und Hinweise ich noch habe, wird man dann in meinem Artikel lesen können.


Erstellt von Jerri | Permalink | Kategorie: konsole, vim | Kommentare
15.05.2006 11:35:42

Social Engineering...

Mit den immer besser werdenden technischen Möglichkeiten der Verschlüsselung wird es immer schwieriger sich unerlaubten Zutritt zu Dokumenten bzw. Services zu holen, indem man versucht, die Schlüssel bzw. Verschlüsselungen zu knacken. Was in diesem Fall aber schon immer wessentlich einfach war und bleiben wird, ist das Erfragen von z.B. Passwörtern von den Personen, die bereits authorisiert sind, die Dokumente und Services zu nutzen. Dieses Umgehen der technischen Sicherheitsmassnahmen durch Ausnutzung der menschlichen Unzulänglichkeiten nennt man "Social Engineering".

Einen kleinen Artikel zu dem Thema hat ein Kollege von mir geschrieben und in seinem Blog gepostet:

Social Engineering - Securitatis.de - Das Plus an Sicherheit

Jetzt werde ich mal schauen, ob ich mit seiner Anleitung das Passwort zu seinem Server bekommen kann, um seine Seite zu defacen... :)


Erstellt von Jerri | Permalink | Kategorie: interessant | Kommentare
14.05.2006 10:40:53

It's game time...

Das hier ist ein Quicky. Manchmal sucht man nichts besonderes im Netz und stolpert dann über Links wie diesen:

c64s.com - play Commodore 64 games online (no download required)

Unglaublich. Aber hier kann man alle C64-Spiele in einem Java-Applet spielen. Gut, die Qualität ist nicht optimal (oder es liegt an meinem Rechner). Aber allein der Gedanke ist fantastisch. C64! Die gute alte Brotkiste. Ich will fast behaupten: Damit hat alles angefangen. Zumindestens bei mir. :)


Erstellt von Jerri | Permalink | Kategorie: interessant | Kommentare
14.05.2006 00:21:04

Ein paar kleine Links zwischendurch...

<iframe src="http://rcm-de.amazon.de/e/cm?t=jerriswelt-21&o=3&p=8&l=as1&asins=0586057242&fc1=000000&IS2=1&lt1=_blank&lc1=0000ff&bc1=000000&bg1=ffffff&f=ifr" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0">

Habe gerade nicht so viel Zeit, wie ich mir gerne wünschen würde und lesen nebenbei auch noch ein paar alte Bücher von Issac Asimov über Roboter. Sehr lesenswert. Sollte man als Science-Fiction-Fan zumindestens mal eines davon gelesen haben. Die Art und Weise, wie Issac Asimov die drei Gesetze der Robotik als Basis für Geschichten nutzt, ist wirklich fantastisch. Nebenbei lernt man auch etwas über sich selbst.

Ansonsten hier noch ein interessanter Link für Homepage-Besiter, die ihre Website noch ein bisschen pushen wollen und ein kleines bisschen in Richtung SEO gehen wollen:

FREE Webmaster Tools - SEO Tools

Man findet auf der Seite ein paar Tools, mit denen man einzelne Infos zur eigenen Website ermitteln kann. Z.B., welchen Pagerank man auf Google hat.

Und für alle diejenigen, die noch ein bisschen mehr aus CSS rausholen wollen, lohnt der folgende Link:

Der Autor dieser Website macht Experimente, wie weit man mit CSS tatsächlich gehen kann. Soweit ich das gesehen habe, darf man alle auf der Website vorgestellten Methoden ohne Einschränkungen auf der eigenen Homepage nutzen. Und was tatsächlich alles mit reinem CSS möglich ist, ist wirklich erstaunlich.


Erstellt von Jerri | Permalink | Kategorie: interessant | Kommentare
09.05.2006 21:27:45

Versionssprung bei vim

Lange hat es wieder gedauert, aber mir scheint, es hat sich gelohnt. Die neueste Version von vim ist endlich offiziell online.

Viele interessante Neuerungen sind scheinbar hinzugekommen. Wie nötig diese Neuerungen sind, wird sich zeigen. Ich hatte bisher eigentlich nicht das Problem, dass mein Editor nicht genug kann. Aber wer weiss. Vielleicht sind es die Neuerungen, die ich mir schon immer gewünscht habe, obwohl ich nicht wusste, dass ich sie mir gewünscht habe.

Und um die Neuerungen gleich richtig sehen zu können, hat ein User auf der vim-Mailingliste mal einen kleinen Blog-Eintrag gepostet, der die wichtigsten Neuerungen grafisch darstellt:

amix.dk : Vim 7 - the graphical introduction

So wie es aussieht, sind einige Sachen endlich in den Editor integriert worden, die vormals mit Hilfe von Skripten und Plugins gelöst wurden. Dadurch ist natürlich der Ablauf beim Arbeiten etwas einfacher. Wir werden sehen. Auf jeden Fall bedeutet es nun mal wieder die .vimrc durchzusehen und evtl. zu überarbeiten. :)

Bin gespannt, wann die neue vim-Version als Debian-Paket für sarge zur Verfügung steht.


Erstellt von Jerri | Permalink | Kategorie: vim | Kommentare
07.05.2006 15:59:34

Nichts los...

Ich bin momentan geschlagen von meinem Frühlings-Heuschnupfen, der hoffentlich bald überstanden ist. Da der Winter dieses Jahr so lange gedauert hat, geben jetzt alle Pflanzen gleichzeitig Vollgas und verschliessen mir Nase und Augen. X-(

Der Artikel zum Thema Screen ist scheinbar sehr gut angekommen und ich plane bereits meinen nächsten Artikel zum Thema "Arbeiten (fast) ohne Maus". Leider momentan noch nicht viel gemacht, weil ich mich eben mit dem Heuschnupfen rumschlage.

In meinen Logfiles habe ich bereits gesehen, dass ich jetzt von diversen Stellen im Netz verlinkt werden. Sehr schön. Das sieht man doch gerne. Und um das ganze noch genauer zu sehen, kann man den folgenden Link ausprobieren:

Who links to me?

Ein kleines Tool im Web welches diverse Informationen zu einer Domain abfrägt und gebündelt darstellt.


Erstellt von Jerri | Permalink | Kategorie: homepage, allgemein | Kommentare
04.05.2006 19:49:21

Noch ein paar Konsolen-Links

Nachdem mein letzter Artikel richtig gut abgegangen ist. :) Hier noch ein paar interessante Links zum Thema Konsolen-Tools. Zum einem ein Link mit zusätzlichen keinen Tools, die die Arbeit in mutt verbessern:

Meine "must have"-Tools fuer Mutt - The dark side of life..

Und zum anderen einen Link, den ich schon immer gesucht habe. Ein Wiki zum Thema screen:

GNU screen: start

Schade ist, dass ich irgendwie keine Seiten-Kommentare auf meinen Artikel bekommen habe (also unten an der Seite). Funktioniert da etwas mit dem Kommentier-Tool nicht?


Erstellt von Jerri | Permalink | Kategorie: konsole, interessant | Kommentare
02.05.2006 22:41:44

Scripting screen for fun and profit... :)

This article is written in english and rather long. First of all to improve my written english. But more importantly to get a bigger audience for this article. :-) I hope my english is not that bad.

People reading my blog know that I am a console-cowboy, meaning I mainly use console tools to do my work. As every cool console-cowboy naturally I use screen to manage my applications and displays.

I assume people reading this article already know about screen and its benefits and just want to learn how to get more out of it. But for all those people who don't know about screen or why to use it, here are some random benefits:

  • screen detaching (safenet if you have a flaky network connection)
  • saving screen real estate
  • no need to use the mouse (everything can be done with the keyboard)
  • using the scrollback buffer you can view and search in the output of commands
  • using detached screens you can put interactive console tools into the background, like a daemon
  • many others I can't remember just now

Gnu screen is a very powerful tool and has a lot of features which are sometimes not that easy to grasp. But investing some time into learning it can speed up your workflow a lot!

Gnu Screen

An introduction to screen can be found here:

GNU Screen: an introduction and beginner's tutorial

Basics of screen scripting

OK. Enough chit chat. Lets get down to business. Most of the time you will use screen interactively. You want another screen windows, you press the buttons. But maybe unknown to some, screen is in some sort scriptable. It unfortunately is not straightforward and the very good manual gives only hidden hints. But if you know the edges it's quite helpful.

screen -X

The first and basic parameter you need to know is -X. With this parameter you can send screen commands to any screen session (for a list of screen commands take a look at the very fine man page for screen). By default it uses the screen session you are currently attached to. So just to test this, start screen, create a second window pressing C-a c. Now enter the following line at the shell prompt:

$ screen -X next

Wow. You just left the current window and went to the next window. This is the same as pressing C-a n or C-a :next<CR>. Impressive, isn't it? :)

Where could this be used. Consider a program which needs a very long time to complete. You could start it inside a screen in the following way:

$ longrunningapp.sh; screen -X select <thiswindownumber>

You can get the windownumber by pressing C-a w. It's the number right in front of the name of the screen which is marked by the star. If your windows have distinct names you can also use the name as parameter for the select command!

This line starts the application. After the application finishes the screen session focuses on the applications window, which means you will be automatically brought to that window. You don't lose time looking and looking whether the application already finished. In the meantime you can continue work in another window.

screen -X -p

We just talked about different windows and their names/numbers. Consider the screen command stuff. It is used to send keystrokes to a window. By default the current window is used as the target. But this command is not very helpful if used interactively like

$ screen -X stuff hello

This way you can write notes to yourself. But if you add the parameter -p to this line you can send those commands to another window in the same screen session. Now this is helpful. You can remote control applications in windows this way. Consider the following example:

Create a screen-window and start e.g. w3m in it to show a webpage which changes over time (w3m is a console web browser like lynx or links). This could be a webpage showing usage statistics or stock information on the net or whatever. For this example we will use a page which shows the current weather for munich:

$ w3m http://www.meteo24.de/wetter/49X7464.html

This will output the current temperature etc. for munich. Unfortunately this display is not updated automatically. You manually have to reload the page. Let's see how screen can help us.

Give the window a distinct name or just use the number of the screen window. To rename the current window to another name press C-a :title watchit. The current screen window now has the name "watchit". Enter C-a w to check this.

Now comes the interesting part. Go to another window in your screen session. To reload the website in w3m you have to enter R (Shift-r). So using the following line we periodically send R to the w3m-window which then reloads the website and updates the display.

$ while true; do screen -p watchit -X stuff R; sleep 5m; done

The sleep-command is used to reload the webpage only once every 5 minutes. You can enter nearly any value here. See man sleep for more information about sleep.

As you can see we now can remote control w3m. This might be a very simple example for remote controlling. With some experimentation you will certainly find more uses for this technique. Remember that w3m was just an example. We really only sent keystrokes to the other window. So any console tool can in principle be remote controlled using screen.

screen -X -p -S

Now lets take another step and remote control windows in other screen sessions. Remember that screen can be started on several terminals which creates several screen instances on your computer. You can see those screen-instances using screen -ls

$ screen -ls
There is a screen on:
        1840.pts-0.work (Attached)
        6027.pts-5.work (Attached)
2 Sockets in /var/run/screen/S-gerhard.

As with windows in screen sessions, several screen instances (called sessions) can be identified by their number and their name. You can give a new screen session another name than the default one (which is the name of the tty it is started in) by adding the parameter -S at the command line (you have to be outside screen to start a new session!).

$ screen -S mysession

If you now run screen -ls you will see something like this:

$ screen -ls
There are screens on:
        1840.pts-0.work (Attached)
        6027.pts-5.work (Attached)
        6203.mysession  (Attached)
3 Sockets in /var/run/screen/S-gerhard.

Other information in this output is whether the session is currently attached (meaning if it is currently shown on any terminal) or detached. Detached screen sessions are still running like attached screen sessions, but are not displayed anywhere.

Now to send a screen command to a certain screen session you can use:

$ screen -S mysession -X stuff hello

Try it and you will find the word hello in the currently open window in the other screen session.

Together with the -p parameter we now are able to send any screen command to any screen session (which is owned by yourself. screen does have some multiuser capabilities. But to describe them I will have to do another tutorial someday). The screen sessions have to run on the same computer though!

Environmentvariable $STY

To get the current identifier of the screen you are currently in, you can read the environment-variable $STY. This way you have an identifier from inside scripts.

$ echo $STY
1840.pts-0.work

This environment-variable can also be used to check if your scripts is currently running inside an screen session. Be aware that if you change the name of the screen session via C-a :sessionname myname only screen -ls will show the correct name. $STY still will show the name the session had on starting it.

A thing to look out for

On thing to keep in mind while scripting screen is to be aware, that commands send to screen via the screen-command might not be finished when the commands returns. They might not even have worked correctly. The commands are put into a queue where they are execute when possible. So you don't know wether a command was received, when it will be executed and if the execution was successful. The screen -X command works asynchronous. Take a look at the window-content-example below which demonstrates this point.

Examples for simple screen scripting

The following are simple examples on how to use screen scripting to do some things. I am expecting you to use bash as your shell. You might have to convert the examples to other shell environments if you are not using bash.

Checking if you are inside a screen session

$ if [ -n "$STY" ]; then echo 'We are inside screen'; fi

Getting the contents of a window

Using the hardcopy-command you can send the content of a screen window to a file for further observation. This way you e.g. could check in what state a remotely controlled application currently is. Be aware, that on exiting the screen-command doesn't mean, the file is created! Unfortunately you have to wait for it to be created. Normally if you just sleep for some time after issuing the command should be enough. But you could also check for the file in a tight loop.

$ screen -S screenname -p windowname -X hardcopy /tmp/filename; sleep 1s; cat /tmp/filename

You can also get the whole content of the scrollback buffer if you add -h to the hardcopy-command.

The output in the filename also contains the screen status bar, if turned on. This can be used to check which window the screen session was in when the command hit it. Naturally you have to output the window name in the status bar to do this. :)

Running a screen window dia-show

Suppose you have several running console applications which output different changing data. As a screen lover you put them in several windows. If you want to see the output every now and then, you manually have to switch to all the windows and take a look (obviously you also could split the screen, but thats not always possible).

With the following line you can create a simple dia show effect, where every windows is shown for a small amount of time. You only need to now the sessionname of the screen session where the applications are running in. This way your precious data is constantly presented to you.

$ while true; do screen -S sessionname -X next; sleep 10s; done

screen-graph-script

A real script using screen is my screengraph-utility. It is available from this very website with full source code. Effectively it just uses hardcopy to gather the data from the designated screen window and then outputs the found data using gnuplot.

screen graph

Conclusion

You now know how to send noninteractively commands to any screen windows running on your computer. With this knowledge you are able to automate your console tools, even if they are fully interactive. If you create interesting scripts using this technique please tell me. If there are enough ideas I might post another blog entry with those ideas. Just send them to

I hope this article was of some help to anyone. Please post comments if you have annotations or if you find something that is wrong.

Edits

  • Example with long running example was wrong (2012-08-22).

Erstellt von Jerri | Permalink | Kategorie: konsole, interessant | Kommentare