Hello,
I'm trying to create a really simple, no-frills script that opens up multiple ssh sessions to multiple servers, and I'm trying to make it all happen in a single Terminal session in multiple Terminal tabs. In addition, I am trying to learn bash scripting and trying to make my script as generic as possible, with the only changes being the command being run (so I can reuse my script/share it).
Anyway, like I said, I'm still learning, and following one the HOW-TOs on
http://www.tldp.org So feel free to explain where I'm missing the "point".
Here's what I've got:
Code:
#!/bin/bash
# Clear the screen
clear
# Launch Terminal with the most commonly used linux servers in tabs
# this is a work in progress...
# Define Servers
echo "Defining servers for $HOSTNAME.example.edu"
echo
servername1="server1.example.edu"
servername2="server2.another.example.com"
servername3="server3.example.edu"
servername4="server4.somewhere.org"
servername5="server5.somewhere.org"
# Short or preferred display names
server1="Web_Server"
server2="Test_Server_and_DHCP"
server3="MySQL_Server"
server4="Monitor_Server"
server5="Snort_Syslog_MRTG_Server"
# Launch the Terminal
echo "Launching the terminals now"
echo
set -x
source ~/.bash_profile
scriptterminal="--title $server1 --command `ssh -l masterc $servername1` \
--tab --title $server2 --command `ssh -l masterc $servername2` \
--tab --title $server3 --command `ssh -l masterc $servername3` \
--tab --title $server4 --command `ssh -l masterc $servername4` \
--tab --title $server5 --command `ssh -l masterc $servername5`"
Terminal $scriptterminal
set +x
echo "All set"
echo
I've actually done it a few different ways, moving the "scriptterminal" variable into one command (removing the \) removing the scriptterminal and just running it directly (terminal --title...) and the variations don't work. The results are basically the same, I run the script, it hits the point of running the ssh commands and just sits there. I have to kill it (not CTRL C, but actually ps, kill -9 from another terminal).
I've got auth keys setup, so it's not waiting for password input, it just seems 'stuck'. I've seen various scripts around for running remote commands through ssh in scripts, but none of them work for just opening up an ssh session and keeping it open.
Any thoughts? And I know there are a couple thousand of you genius folks who could write this up for me, and if you do, thanks. But I'd very much like to learn what I'm doing wrong, and if you write it up different, I'd like to learn how your version works; so please be verbose in your response.
Thanks!
-Chad