LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
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 12-18-2008, 10:37 AM   #1
Mr Pink
LQ Newbie
 
Registered: Dec 2008
Posts: 23

Rep: Reputation: 0
Bash script - syntax error: unexpected end of file


Hello,

I am having a few problems with a script I am trying to write which monitors ssh tunnels and brings them back up if they die.

Here is the code

Code:
#!/bin/bash



DOWN=`echo "Tunnel Down"`

TUNNEL1=`ps ax | grep "2080:192.168.20.11:80" | grep -v grep | wc -l`
TUNNEL2=`ps ax | grep "2080:192.168.20.12:80" | grep -v grep | wc -l`
TUNNEL3=`ps ax | grep "2080:192.168.20.13:80" | grep -v grep | wc -l`
TUNNEL4=`ps ax | grep "2080:192.168.20.14:80" | grep -v grep | wc -l`
TUNNEL5=`ps ax | grep "20000:192.168.21.10:20000" | grep -v grep | wc -l`

for tunnels in $TUNNEL1 $TUNNEL2 $TUNNEL3 $TUNNEL4 $TUNNEL5

do

if [ $tunnels -eq 1 ]
then
     echo "$(date) SSH $tunnels up"
else
    echo "$tunnels $DOWN $(date)"
fi
As you will see it isn't very intelligent in the fact you can't tell which tunnel has gone down so there is no way of bringing it back up. I am running out of ideas on how I can approach this so any help would be gratefully received.

Thanks,
Mr P

Last edited by Mr Pink; 11-18-2010 at 06:04 AM. Reason: removed details
 
Old 12-18-2008, 11:05 AM   #2
xowl
Member
 
Registered: Jan 2005
Distribution: Slackware current (and others)
Posts: 188

Rep: Reputation: 30
I would use just the IP in the list, but the problem is the last tunnel, something like

servers=192.168.1.1 192.168.1.2

for server in servers
.
.
.

Hope this helps
 
Old 12-18-2008, 11:15 AM   #3
hasanatizaz
Member
 
Registered: Nov 2007
Location: Pakistan
Distribution: Redhat and Debian
Posts: 302
Blog Entries: 1

Rep: Reputation: 34
you are not closing the function of do which is done
just like if and fi
 
Old 12-18-2008, 11:40 AM   #4
Mr Pink
LQ Newbie
 
Registered: Dec 2008
Posts: 23

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by xowl View Post
I would use just the IP in the list, but the problem is the last tunnel, something like

servers=192.168.1.1 192.168.1.2

for server in servers
.
.
.

Hope this helps
Not sure how would this help though? Why would the last tunnel be a problem?

Thanks,
Mr P
 
Old 12-18-2008, 12:51 PM   #5
xowl
Member
 
Registered: Jan 2005
Distribution: Slackware current (and others)
Posts: 188

Rep: Reputation: 30
servers=192.168.20.11 192.168.20.12 192.168.20.13 192.168.20.14

for server in servers
do
tunnel=$(ps ax | grep "20000:$server:20000" | grep -v grep | wc -l)
if [ $tunnel -eq 1 ]
then
echo "$(date) SSH $tunnels up"
else
# You can add what ever you want to take the tunnel up
echo "$tunnels $DOWN $(date)"
fi
done
 
Old 12-18-2008, 06:41 PM   #6
Mr Pink
LQ Newbie
 
Registered: Dec 2008
Posts: 23

Original Poster
Rep: Reputation: 0
Ah yeah nice one, Will just have to add another one for a different port

Thanks,

Mr P
 
Old 12-18-2008, 07:11 PM   #7
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,744
Blog Entries: 54

Rep: Reputation: 2973Reputation: 2973Reputation: 2973Reputation: 2973Reputation: 2973Reputation: 2973Reputation: 2973Reputation: 2973Reputation: 2973Reputation: 2973Reputation: 2973
I'm sure you have reasons to script this but maybe check out "autossh" on Freshmeat or Sourceforge?
 
Old 12-19-2008, 07:31 AM   #8
Mr Pink
LQ Newbie
 
Registered: Dec 2008
Posts: 23

Original Poster
Rep: Reputation: 0
Looks great I have just implemented AutoSSH on the server so I shall see how it goes!

Thanks alot for the suggestion
 
  


Reply


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
Backup Script error "line 31: syntax error: unexpected end of file" eswanepoel General 7 12-07-2007 10:28 AM
Simple bash script "unexpected end of line error" snowman81 Programming 11 11-11-2007 10:31 AM
bash "unexpected end of file" script error Runge_Kutta Linux - General 6 05-23-2007 04:36 PM
/usr/bin/lesspipe: line 223: syntax error: unexpected end of file fakie_flip Linux - Software 1 09-06-2006 03:22 AM
got a syntax error which shows unexpected end of line when tried to run a shell scrip racer_mec Linux - Newbie 1 01-10-2005 02:43 AM


All times are GMT -5. The time now is 04:28 PM.

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