script auto connect multi ssh-server konsole

09/02/2010 by - Bash

#!/bin/bash


## 
## arr dei server  formato 'utente@host |nome_simbolico'  
##
SERVER=('[email protected] |SERVERA' '[email protected] | SERVERB' '[email protected] -p4390 |SERVERC' '[email protected] -p2100 |
SERVERD')



# start a new konsole window and save the handle in $konsole
konsole=$(dcopstart konsole-script)

# maximize the new window
dcop $konsole konsole-mainwindow#1 maximize

# get current session for the first (just created) window
thissession=$(dcop $konsole konsole currentSession)

# rename this window/session
dcop $konsole $thissession renameSession "Scuolazoo  init"


# start a new session tab for each server
for s in "${SERVER[@]}" ; do
srv=`echo $s|awk -F\| '{print $1}'`
name=`echo $s|awk -F\| '{print $2}'`

# this output is displayed on the terminal which is running your script
echo "connect to server: $name"

# create another konsole tab and save handle in $newsession
newsession=`dcop $konsole konsole newSession "ssh $srv"`

# wait for shell startup 
while [ `dcop $konsole $newsession sessionPID` -eq 0 ]; 
do sleep 0.1 
done

# rename the new session
dcop $konsole $newsession renameSession $name

# and start the ssh session
dcop $konsole $newsession sendSession "exec ssh $srv  \"$param\""

done

# close the first session window
dcop $konsole $thissession closeSession > /dev/null


Lascia un commento

Questo sito usa Akismet per ridurre lo spam. Scopri come i tuoi dati vengono elaborati.