Visit Jeremy's Blog.
Go Back > Blogs > Musings on technology, philosophy, and life in the corporate world
User Name


Hi. I'm a Unix Administrator, mathematics enthusiast, and amateur philosopher. This is where I rant about that which upsets me, laugh about that which amuses me, and jabber about that which holds my interest most: Unix.
Rate this Entry

Stupid little konsole trick

Posted 10-07-2009 at 04:21 AM by rocket357
Updated 10-27-2009 at 07:41 PM by rocket357 (doh..."ksh-ism"...)

Ok, so I have a dual-head setup at work (running OpenBSD-4.6), and I am usually ssh'd into dozens of machines at a time. My desktop tends to look like a fuster-cluck of aterms.

So I discovered a cool little trick with konsole. Using dcop, you can open new terminals as a new session (tab) in an existing konsole window and then send commands to said sessions (and even rename the sessions to match what commands you sent to it).

But, there's only one problem. I'm running silly little commands like 'pidof' and such aren't available (which MANY of the dcop scripts utilize, since they're developed in a Linux environment).

Not to worry...ksh is every bit as powerful as bash, and we can solve the problem of 'pidof' with a silly ksh/bash substitution trick.

Here's the script:


# Uncomment the following line to debug:
#set -x

# here's where you'd see "pidof konsole" in a Linux/bash environment...
PID=`ps axc -o pid,command | grep konsole | sed -e 's/^ *//g' | cut -d' ' -f1`

if [[ -z $PID ]]; then # no konsole window open!
        # we need --script so we can use "sendSession" later on...
	konsole --script & 
        # wait a split sec for konsole to open
	sleep 0.1 
        # grab the pid of the new konsole window
        PID=`ps axc -o pid,command | grep konsole | sed -e 's/^ *//g' | cut -d' ' -f1`

# another minor wait, just so konsole is "settled"
sleep 0.1  

# create a new session (tab)
session=$(dcop konsole-${PID} konsole newSession)

# send an ssh command to the new session, using the passed-in variables
dcop konsole-${PID} $session sendSession "$1"

# rename the new session (tab) to whatever you see fit.
dcop konsole-${PID} $session renameSession "$2"
This script assumes a few things:

1) One konsole is open at a time (or, send the commands to the first konsole window found).
2) You have dcopserver running in the background (for those of us who don't use KDE, such as myself. =)


./ "<command_to_run>" <desired_session_name>

The script searches for a konsole window, and if it can't find one, it opens a new one. Once it has an existing (or new) window, it creates a new session, sends command (usually ssh, for me) to that session, then renames the session's tab to whatever you want it set to (i.e. the hostname of the machine you're ssh'ing to).

Pretty cool, methinks. Very useful in ~/.fluxbox/usermenu (and very powerful if you use key-based authentication for ssh)...and it helps keep my desktop from being so clustered.

Now if I could just find an RDP client that tabs similarly, I might actually be able to see my desktop!
Posted in OpenBSD
Views 2273 Comments 0
« Prev     Main     Next »
Total Comments 0




All times are GMT -5. The time now is 06:35 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration