e81c
![]() |
|
|
|
|
|||||||
| Web & Network Services Discussion related to network/web services such as apache, bind, sendmail, etc. |
![]() |
|
|
Thread Tools | Display Modes |
|
#1
|
||||
|
||||
|
Hi guys, Im having trouble finding the way to:
Check the connection if it has been established with timeout:1. Create the connection 2. Check if it has been established 3. If yes, then do something 4. If no, for timeout = 5 seconds, exit with error code. Netcat sounds like a perfect tools for this task: Quote:
Script to telnet web serverPlease see the attachment, I cant post here, for some reasons the forum complained the code with the "bad request" error A similar script I wrote before was working, but unfortunately I forgot to keep copy of it. This time, it doesnt work. I must have syntax errors somewhere.
__________________
...then the God created man... |
|
#2
|
||||
|
||||
|
You could try net/tcping from ports.
Code:
# tcping -t 5 www.google.com 80 www.google.com port 80 open. # echo $? 0 Code:
# tcping -t 5 www.google.com 90 www.google.com port 90 user timeout. # echo $? 2 Code:
if ( tcping -q -t 5 www.google.com 80 ); then echo alive; else echo dead; fi alive if ( tcping -q -t 5 www.google.com 90 ); then echo alive; else echo dead; fi dead
|
|
#3
|
||||
|
||||
|
Thanks, but the script will be run in web server, so I cant install any 3rd party application.
__________________
...then the God created man... |
|
#4
|
||||
|
||||
|
When you say that the timeout switch has no effect, what do you mean? That you never get your prompt back unless you ^C? Try adding the -o switch. Oh, there's also the -z flag to consider.
Last edited by DutchDaemon; December 6th, 2008 at 18:33. |
|
#5
|
||||
|
||||
|
Hi DutchDaemon,
My web server running Linux, there is no -o switch for netcat Let me elaborate a bit more in details. In my case, it takes about 2 seconds to establish a new connection (a deamon with listening port) I run this command in background mode: Quote:
Quote:
__________________
...then the God created man... |
|
#6
|
||||
|
||||
|
I came up with this function:
Code:
repeatCMD () {
count="0"
$@
while [ $? -ne 0 ]; do
sleep 1
echo " ===> I try again..."
count="$(($count + 1))"
if [ $count -eq 5 ]; then
echo " ===> ERR: Max number of retry. Quitting..."
exit 127
fi
$@
done
}
Code:
repeatCMD nc -zw 5 hostname port But Im sure you guys have a more elegant solution. Seriously, 12 line of code for the timeout switch doesnt sound right. And I havent recalled what I have done with the telnet script :S
__________________
...then the God created man... Last edited by bsddaemon; December 7th, 2008 at 14:22. |
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| FreeBSD 7 under VMWare Server 2 - sanity check | hwyhobo | Installing & Upgrading | 14 | September 10th, 2010 14:03 |
| Autodetect sound card (script) | soko1 | Howtos & FAQs (Moderated) | 12 | May 6th, 2009 18:46 |
| DVD rip script for mencoder | kamikaze | Userland Programming & Scripting | 0 | December 2nd, 2008 10:24 |
| Greasemonkey script to un-narrow forum. | hark | Feedback | 5 | November 20th, 2008 20:35 |
| Autodetect network card (script) | soko1 | Howtos & FAQs (Moderated) | 1 | November 18th, 2008 11:46 |