LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices

Reply
 
Search this Thread
Old 12-31-2009, 07:51 PM   #1
VipX1
Member
 
Registered: Jun 2009
Location: Dublin, IRL
Distribution: Arch
Posts: 35
Blog Entries: 1

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


Code:
#!/bin/bash
if  ping -b -c 1 10.0.1.10
then
gnome-terminal -x ssh 10.0.1.10
else
gnome-terminal -x ssh www.mywebserver.com
fi
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
bartonski
Member
 
Registered: Jul 2006
Location: Louisville, KY
Distribution: Fedora 12, Slackware, Debian, Ubuntu Karmic, FreeBSD 7.1
Posts: 443
Blog Entries: 1

Rep: Reputation: 47
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:

Code:
#!/bin/bash
gnome-terminal -x (ssh 10.0.1.10 || ssh www.mywebserver.com)
[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
VipX1
Member
 
Registered: Jun 2009
Location: Dublin, IRL
Distribution: Arch
Posts: 35
Blog Entries: 1

Original Poster
Rep: Reputation: 15
Code:
gnome-terminal -x ssh 10.0.1.10 && gnome-terminal -x ssh www.mywebserver.com
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.
 
  


Reply

Tags
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


All times are GMT -5. The time now is 09:49 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration