LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 01-24-2012, 10:09 AM   #1
oscarenzo
LQ Newbie
 
Registered: Jan 2012
Posts: 10

Rep: Reputation: Disabled
bash script to check telnet status


Hello guys,

Before to looking for in the web, i arrive here for help:

Look i have 2 servers running any service, as can be apache, that is running on the port 80, i would like do an script for from the server B, can check the 80 port of the server A, if is running, do:

service httpd stop

If the server B is not listening on the port 80, will start the httpd service
service httpd start

i have this code now:
Code:
if telnet -c 65.254.46.206 80 </dev/null 2>&1 | grep -q Escape; then
  echo "Connected"
  service httpd stop
else
  echo "no connection"
  service httpd start
fi
when the server B is not working, working fine, but when is working, take more time, trying, before any minutes do the echo and stop the service, are there any trick or way for reduce the time, by example check by 2 seconds only, if on 2 seconds not respond, do the condition.

thank you very.
 
Old 01-24-2012, 10:31 AM   #2
rodrifra
Member
 
Registered: Mar 2007
Location: Spain
Distribution: Debian
Posts: 201

Rep: Reputation: 36
Use nmap to check port's status.
 
Old 01-24-2012, 10:45 AM   #3
oscarenzo
LQ Newbie
 
Registered: Jan 2012
Posts: 10

Original Poster
Rep: Reputation: Disabled
thank you

for how? can you explain to me a bit more?
 
Old 01-24-2012, 11:11 AM   #4
oscarenzo
LQ Newbie
 
Registered: Jan 2012
Posts: 10

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by rodrifra View Post
Use nmap to check port's status.
i tested using nmap, but this tool check if the port is open but now if the service is runing :S

other advice?
 
Old 01-24-2012, 11:15 AM   #5
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 242Reputation: 242Reputation: 242
You could use netcat if you have it

Code:
if nc -z -w2 65.254.46.206 80 2>/dev/null; then
  echo "Connected"
  service httpd stop
else
  echo "no connection"
  service httpd start
fi
edit: removed unwanted -c option that came from pasted IP from OP's post :/

Last edited by Cedrik; 01-24-2012 at 11:28 AM.
 
Old 01-24-2012, 11:18 AM   #6
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 242Reputation: 242Reputation: 242
Quote:
Originally Posted by oscarenzo View Post
i tested using nmap, but this tool check if the port is open but now if the service is runing :S

other advice?
If the port is open that means a program/service listens to it
 
Old 01-24-2012, 12:52 PM   #7
oscarenzo
LQ Newbie
 
Registered: Jan 2012
Posts: 10

Original Poster
Rep: Reputation: Disabled
work okay

Quote:
Originally Posted by Cedrik View Post
If the port is open that means a program/service listens to it
yes sorry, i tested in my V and work okay, but the problem now is that my provider use virtuozzo and when i run my script appear errors ad:

operation not permitted.

i would like thta you can help me do this script using telnet, is possible?

the idea for this script is set a cron for run each 5 minutes, and test if the service if running on the other server, is not runing, start the same service on this server, as this script will run each 5 minutes, for avoid that start again the service, check if the service if runing, if is runing and the service in the other service still down, not should do nothing.

please help me

Last edited by oscarenzo; 01-24-2012 at 12:54 PM.
 
Old 01-24-2012, 02:32 PM   #8
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 242Reputation: 242Reputation: 242
What operation is not permited ?
 
Old 01-24-2012, 02:43 PM   #9
oscarenzo
LQ Newbie
 
Registered: Jan 2012
Posts: 10

Original Poster
Rep: Reputation: Disabled
Unhappy

Quote:
Originally Posted by Cedrik View Post
What operation is not permited ?
use nmap :s
 
Old 01-24-2012, 02:45 PM   #10
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 242Reputation: 242Reputation: 242
Do you have netcat installed ?
Code:
type nc
 
  


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
[SOLVED] Adaptec ARCCONF RAID array check script emailing status lithos Linux - Software 1 10-03-2011 03:27 PM
[SOLVED] SQL Script to check status of last command vikas027 Programming 2 08-15-2009 06:27 PM
Need to write a shell script which will check the GUI login and retuen the status cod bhsk_08 Linux - General 2 10-14-2008 02:08 PM
Web based script to check a domain status nixhit Programming 2 10-14-2008 09:38 AM
Need program/script to check server status thetawaverider Linux - Software 1 02-27-2007 01:58 PM


All times are GMT -5. The time now is 10:13 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration