LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-15-2007, 01:59 PM   #1
MasterC
LQ Guru
 
Registered: Mar 2002
Location: Salt Lake City, UT - USA
Distribution: Gentoo ; LFS ; Kubuntu ; CentOS ; Raspbian
Posts: 12,613

Rep: Reputation: 69
Run intractive ssh session in a bash script


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
 
Old 10-15-2007, 04:57 PM   #2
raskin
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: approximately NixOS (http://nixos.org)
Posts: 1,900

Rep: Reputation: 69
ssh is rather suspicious - it checks kind of its input file descriptor sometimes.
Does just 'Terminal --command ssh ...' work? Try prepending 'strace -f -o log' and see what ssh actually checks about it. You can even take chances and strace your entire script.
 
Old 10-15-2007, 05:08 PM   #3
MasterC
LQ Guru
 
Registered: Mar 2002
Location: Salt Lake City, UT - USA
Distribution: Gentoo ; LFS ; Kubuntu ; CentOS ; Raspbian
Posts: 12,613

Original Poster
Rep: Reputation: 69
Hey, that's a great idea! Thanks for the response, I think I'm having problems sending the ssh command string as a whole; it seems terminal is taking the parameters that I send to ssh as being sent to Terminal.

Thanks a ton, I think I can work on it further/figure it out from here.

-Chad

{Edit}
Excellent! It was as stupid as using double quotes instead of backticks... Again, thanks for the help.
{/Edit}

Last edited by MasterC; 10-15-2007 at 05:09 PM. Reason: Update
 
  


Reply

Tags
bash, script, session, ssh, tabs, terminal


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to run a program in an ssh session that will run after you close out the session? dr_zayus69 Linux - Networking 5 03-05-2006 07:15 PM
how to have bash script check whether it's a x session? bkeeper Linux - Newbie 9 02-21-2006 06:31 AM
how to run one bash script from within another? babag Programming 9 04-28-2005 12:12 AM
bash script suggestions for waiting for ssh -L iggymac Programming 4 03-22-2005 07:04 PM
Cannot find or run the base session script buldir Fedora 1 06-04-2004 08:14 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:59 AM.

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