Re: ssh to multiple servers in seperate tabs in Konsole with one bookmark or script?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



JW wrote, On 08/05/2008 12:29 PM:
...
For example a command to open up a new Konsole, and open up a new tab for each server and make a ssh connection to that server and name that tab with the server's name. One tab per ssh connection/server

I've googled around and seen several scripts for opening a bunch of tabs, and even naming the tabs, but none of them do that AND make a ssh connection inside the tab.

Does anyone know how to do this?

JW,

You *might* want to look at https://computing.llnl.gov/linux/pdsh.html

You can run an interactive "Do this on many hosts at once" prompted
session, but it's all in one terminal.  Using the 'fanout=1' option each
command is dispatched sequentially to each host, otherwise the dispatch
is in parallel and you can end up with tagged, but intermixed output
lines).  There are plenty of other multiplexed command dispatching
programs, some, which i believe open terminals for each connection.
(e.g. conman clusterssh distribulator dsh gsh mass mussh tentakel...)

I'm including some scripts i'm working on that are, as yet, rather
simplistic and imcomplete, but which might be of value to you.

'konssh' is supposed to (at some point) be able to activate a new
konsole window and/or session tab that 'ssh's' to a host with optional
arguments.

I create a konsole session type that binds to this script, so i can pull
up a "New Konssh" that uses kdialog to prompt for the arguments after
the new tab opens.  It can also be called from the command line (in a
konsole "shell" tab or an xterm or mini-cli...)

There's currently minimal support for starting a new konsole (one
session tab only)

I'm working out the means to hunt down and find a konsole window and/or
tab based upon a search criteria. that's in the 'koninfo' script. (data
collection on konsole info only at this point).

What i want to be able to ultimately do at some point, is be able to
reattach to a konsole tab by searching a konsole Caption and Tab name
and have the KDE window manager change desktops and application focus
and Konsole session tab "active" state to the match.  I'm not quite
there yet ;)

Unfortunately, i'm afraid that 'dcop' may be obsoleted in KDE4 and i'd
have to re-do this in 'dbus'. 'dbus' looks infinitely more contorted
(well, much more verbose and difficult to access)

--stephen

--
Stephen Dowdy  -  Systems Administrator  -  NCAR/RAL
303.497.2869   -  sdowdy@xxxxxxxx        -  http://www.ral.ucar.edu/~sdowdy/

#!/bin/sh
# Title: konssh
# Description: invoke a konsole tab to start an ssh session
# Author: Stephen Dowdy (sdowdy@xxxxxxxx)
# Caveats:  work-in-progress

# TODO: if KONSOLE_DCOP* not set, startup a new Konsole
#       possibly searching for existing konsole

is_debug() { [ "$DEBUG" == 1 ] ;}
debug() { is_debug && echo "DEBUG: " "$@" 1>&2 ;}

prog=$(basename $(readlink -f $0))
debug "Being called as ${prog}"

case ${prog} in
    ks|konssh)
        : # 
        ;;
    kst|konssht)
        : # Open a new session in a tab
        ;;
    *)
        echo "Whatchou talkin' 'bout willis?"
        exit 1
        ;;
esac
if [ $# == 0 ]; then
    ssh_opts="$(kdialog --inputbox 'Remote Hostname and SSH options' '')"
else
    ssh_opts="$@"
fi
ssh_host=$(expr "$ssh_opts" : '.* \+\(.*\)')
ssh_host=${ssh_host:-${ssh_opts}}

# This code still needs some work, obviously
if [ -z "${KONSOLE_DCOP_SESSION}" ]; then
    debug "Creating new Konsole window"
    # Have to look into the security issues of starting "--script"
    # Also, dcopstart can't take cmd args for the exec'd binary :-(
#    KID=$(dcopstart konsole --script)
    debug "Calling : konsole --noclose -e ssh ${ssh_host} ${ssh_opts}"
    konsole --noclose -e ssh ${ssh_opts}  &
    KID="konsole-$!"
    KSID="session-1"
    debug "Calling : dcop ${KID} ${KSID} renameSession ${ssh_host}"
    dcop ${KID} ${KSID} renameSession ${ssh_host}
    exit 0
else
    KID=$(expr "${KONSOLE_DCOP_SESSION}" : '.*(\([^,]*\).*')
    KSID=$(expr "${KONSOLE_DCOP_SESSION}" : '[^,]*,\([^)]*\).*')
fi

dcop ${KID} ${KSID} renameSession ${ssh_host}


# This must be passed to the REMOTE konsole if we started one
# (i.e. we aren't already running in the konsole session)
exec ssh ${ssh_opts}

exit 0

: <<END_NOTES
----------------------------
Look at using '--script'.  that gives the ability to make dcop calls to a running
konsole to do things like feed input to a konsole tab you created with newSession

#  konsole --title "titleDPG" -T "TDPG" --name nameDPG --caption captionDPG 
# nameDPG becomes a dcop referencable target, captionDPG replaces "Konsole <N>"
# in the titlebar (yay!)

#dcop konsole-8992.konsole-mainwindow#1.setCaption(Qstring)
# sets only the session caption, and not permanently, apparently :-(

kde-config --path data
/home/sdowdy/.kde/share/apps/:/usr/share/apps/

check $kde_data_path/konsole   for a .desktop file we can call
for "konssh.desktop" in a 

dcop ${KID} konsole newSession konssh

----------------------------
END_NOTES
#!/bin/sh
# Konsole Information reporter
# This is work-in-progress to support a konsole-switcher
# application that allows you to use cmd-line patterns to
# warp back to any particular konsole window and konsole
# session tab running on your desktop.

# e.g.
#    konswitch dpg-server
#      Found:
#       1) ssh dpg-server
#       2) vim dpg-server.config
#       select ?

is_debug() { [ "$DEBUG" = 1 ] ;}
debug() { is_debug && echo "DEBUG: $@" 1>&2 ;}

for kon in $(dcop konsole\*); do
  echo "-------------------------"
  koncur=$(dcop ${kon} konsole currentSession)
  debug koncur=${koncur}
  sessnames=""

  echo "name==[$(dcop ${kon} konsole-mainwindow#1 name)]"
  echo "caption==[$(dcop ${kon} konsole-mainwindow#1 caption)]"
  echo "windowid==[$(dcop ${kon} konsole-mainwindow#1 getWinID)]"


#  for konsess in $(seq 1 $(dcop ${kon} konsole sessionCount )); do
  for konsess in $(dcop ${kon} | grep '^session-' ); do
    debug konsess=${konsess}
    sessnames="${sessnames} $(dcop ${kon} ${konsess} sessionName)"
    if [ "${konsess}" == ${koncur} ]; then
      echo "${kon}:${konsess}:*Name=$(dcop ${kon} ${konsess} sessionName)"
    else
      echo "${kon}:${konsess}: Name=$(dcop ${kon} ${konsess} sessionName)"
    fi
  done
#  echo "Session Names are: ${sessnames}"
done

#dcop konsole-3570 session-2 sessionName

exit 0

: << END_NOTES

dowdy@debian:~$ koninfo
konsole-3657:1: Name=Shell
konsole-19416:1: Name=Shell
konsole-19431:1: Name=Shell
konsole-19431:2: Name=Shell No. 2
konsole-3688:1: Name=VPN
konsole-3688:2: Name=root@das-ingest

END_NOTES
___________________________________________________
This message is from the kde mailing list.
Account management:  https://mail.kde.org/mailman/listinfo/kde.
Archives: http://lists.kde.org/.
More info: http://www.kde.org/faq.html.

[Index of Archives]     [Trinity (TDE) Desktop Users]     [Fedora KDE]     [Fedora Desktop]     [Linux Kernel]     [Gimp]     [GIMP for Windows]     [Gnome]     [Yosemite Hiking]
  Powered by Linux