LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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, 09: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 05:04 AM. Reason: removed details
 
Old 12-18-2008, 10: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, 10:15 AM   #3
hasanatizaz
Member
 
Registered: Nov 2007
Location: Pakistan
Distribution: Redhat and Debian
Posts: 317
Blog Entries: 1

Rep: Reputation: 35
you are not closing the function of do which is done
just like if and fi
 
Old 12-18-2008, 10: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, 11:51 AM   #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, 05: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, 06:11 PM   #7
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
I'm sure you have reasons to script this but maybe check out "autossh" on Freshmeat or Sourceforge?
 
Old 12-19-2008, 06: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



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 09:28 AM
Simple bash script "unexpected end of line error" snowman81 Programming 11 11-11-2007 09:31 AM
bash "unexpected end of file" script error Runge_Kutta Linux - General 6 05-23-2007 03:36 PM
/usr/bin/lesspipe: line 223: syntax error: unexpected end of file fakie_flip Linux - Software 1 09-06-2006 02: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 01:43 AM

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

All times are GMT -5. The time now is 02:46 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