Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 12-31-2009, 07:51 PM   #1
Registered: Jun 2009
Location: Dublin, IRL
Distribution: Ubuntu Budgie
Posts: 36
Blog Entries: 1

Rep: Reputation: 15
Smile Bash script, if else statement to ping & ssh connection to correct i.p.

if  ping -b -c 1
gnome-terminal -x ssh
gnome-terminal -x ssh
That's what is inside my .sh file that my 'Taskbar launcher' points to..

Result, if I am on the same local network as my web server
else I am at home the launcher still works.

However, the scripts always suffers from a slight delay while the ping result is sought regardless of where I am dialing in from.
If I just have the blue line in the .sh file and connect from home the connection time is impressive (I use Keys). I'd like to retain that connection time.

Can anyone improve on the way I am establishing which i.p./domain to use?
Old 12-31-2009, 09:27 PM   #2
Registered: Jul 2006
Location: Louisville, KY
Distribution: Fedora 12, Slackware, Debian, Ubuntu Karmic, FreeBSD 7.1
Posts: 443
Blog Entries: 1

Rep: Reputation: 48
This is a job for dnsmasq (lightweight DNS server, good for home LAN).

If you don't want to do this, I would try this:

gnome-terminal -x (ssh || ssh
[edit: nope, doesn't work, and doesn't seem to want to, no matter how I quote it]

Last edited by bartonski; 12-31-2009 at 09:38 PM. Reason: why oh why do the tenses for my verbs not agree?
Old 12-31-2009, 11:05 PM   #3
Registered: Jun 2009
Location: Dublin, IRL
Distribution: Ubuntu Budgie
Posts: 36

Original Poster
Blog Entries: 1

Rep: Reputation: 15
gnome-terminal -x ssh && gnome-terminal -x ssh
This way opens 2 x terminal windows. I then configure the particular servers in /etc/ssh/ssh_config to try for 3 x seconds and close the terminal.
The successful connection stays open.
A bit messy...

Last edited by VipX1; 12-31-2009 at 11:08 PM.


bash, ssh

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
Bash Script to log off of ssh connection Betzie Programming 4 07-07-2009 04:29 PM
Strange if statement behaviour when using bash/bash script freeindy Programming 7 08-04-2008 06:00 AM
ssh - how to close connection from bash script babag Linux - Networking 7 05-30-2008 09:14 PM
Bash: Print usage statement & exit; otherwise continue using Bash shorthand operators stefanlasiewski Programming 9 02-07-2006 05:20 PM
Need help adding an IF / ELSE statement to my Bash Script Relix Linux - General 1 08-01-2002 02:03 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:37 PM.

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