Konsole – the scriptable terminal emulator
Konsole, the terminal emulator of KDE, is scriptable via DCOP (the IPC mechanism of KDE3). I use this feature to start a Konsole session with several tabs. Each tab has its title set to a meaningful name and possibly a command executed. I use this when running an application in JBoss. In the first tab JBoss is run, in the next I let the JBoss log scroll through, in the next I watch the application log, and so on. You may find your own usage for tasks you do daily.
One “trick” is to start Konsole with the --script option. Only then (for security reasons) will it let you send commands via DCOP that are executed in the shell.
This is the shell script I use:
#!/bin/sh
function createSession() {
dcop=$1; shift
title=$1; shift
session=$($dcop konsole newSession)
sleep 0.2 # ugly, but necessary
$dcop $session renameSession "$title"
for each in "$@"; do
$dcop $session sendSession "$each"
done
}
JBOSS=/opt/jboss
LOG=$JBOSS/server/default/log
konsole --script &
pid=$!
sleep 1
dcop="dcop konsole-$pid"
$dcop "konsole-mainwindow#1" maximize
session=$($dcop konsole currentSession)
$dcop $session renameSession "jboss-run"
$dcop $session sendSession "cd $JBOSS/bin"
createSession "$dcop" "jboss-log" "cd $LOG" "less server.log" "F"
createSession "$dcop" "app-log" "cd $LOG" "less application.log" "F"
createSession "$dcop" "tmp" "cd /tmp"
If you need more tabs add more createSession lines. You can add a variable number of commands that are to be executed in the tab. As you can see with the less command, you can also send simple keystrokes to the started programs.
link (0 Kommentare) ... comment
Thema: Shell