Hi. I'm jon.404, a Unix/Linux/Database/Openstack/Kubernetes Administrator, AWS/GCP/Azure Engineer, 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: *nix.
Stupid little konsole trick
Posted 10-07-2009 at 03:21 AM by rocket357
Updated 10-27-2009 at 06:41 PM by rocket357 (doh..."ksh-ism"...)
Updated 10-27-2009 at 06: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 OpenBSD...so 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:
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. =)
Usage:
./konsole_script.sh "<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!
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 OpenBSD...so 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:
Code:
#!/bin/sh # 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` fi # 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"
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. =)
Usage:
./konsole_script.sh "<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!
Total Comments 0