Visit Our UNIX and Linux User Community


Testing connection with a script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Testing connection with a script
# 1  
Old 09-07-2009
Testing connection with a script

I have a box that has to start dhcpd when a certain connection is down and stop the dhcpd when the connection is up again. I would appriciate any help making this script:

From server A:

ping server B
if connection is ok then do nothing
if connection is not ok then start dhcpd
until connection to B is up again

Regards kim jensen
# 2  
Old 09-08-2009
Welcome to the forum !

This is just a hint and am not very thorough with this.

Ping works using ICMP and a host might be still up and not accepting/responding to ICMP packets, in such cases ping might not help with. Instead, check if the destination ip is reachable. If that is so, start the process from the local host where request is initiated.

Let us know, how it goes Smilie
# 3  
Old 09-08-2009
Hello there,
thank you for the reply! I guess I didn't make myself clear.
I only need to test if the connection is up the 'aliveness' of the B
server is uninteresting at this point.

I have tryed something like this:

#!/bin/bash
ping hostB -c3 -W3 > /dev/null
echo $? > A
if grep 0 /home/sipp/A > /dev/null
then exit;
elif
grep 1 /home/sipp/A
then
until grep 0 /home/sipp/A > /dev/null
do
[a command]
done
fi

my problem is that the loop keeps looping even if the connection is up again?

Regards KimJ
This User Gave Thanks to KimJensen For This Post:
# 4  
Old 09-08-2009
No need to redirect output of $? to a file "A" and then grep from that.
Instead use it directly in 'if' block
Code:
if [ $? -eq 0 ];
then
# stuff to do
fi

This User Gave Thanks to matrixmadhan For This Post:
# 5  
Old 09-08-2009
-thanks again
I do learn from this Smilie

My plan is to execute the script every minute by a cronjob that works fine. But the thing is that I made an infinite loop and I don't know how to get out of it again when the connection is up again ?
# 6  
Old 09-08-2009
you miss a lot about how does work a daemon...
I do too: AFAIK
a daemon is still listening, ever, at what ever could come to it by its port...
# 7  
Old 09-08-2009
daPeach thank you for the reply
my aim is this:
B is primary dhcp server
if A server have connectivity to the B server then nothing
If A server have no connectivity to the B server, it should start dhcpd -until connection to B server is up again..

Previous Thread | Next Thread
Test Your Knowledge in Computers #584
Difficulty: Easy
Binary files generally requires less space and are more efficient to process.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script Testing

Hello Scripting Czars I have written one script, which does the Openssl Connection test to 1000's of server's , but before it finally takes off , its error-ring out, kindly take a look into this. #!/bin/bash #Script to Test Connectivity withListen Address & Port Address #Script... (10 Replies)
Discussion started by: raghunsi
10 Replies

2. Shell Programming and Scripting

testing postgres connection in shell script

I have a script that does db query in postgres. I'm trying to put in some error checking in the script. I keep running into the password prompt problem where when invalid credentials/or database is put it, it would prompt me for a password which hangs the script. Is there a way that I can check for... (0 Replies)
Discussion started by: zerofire123
0 Replies

3. Shell Programming and Scripting

Package version testing script

I was wondering if anyone already had a script to check rpm packages versions x.x.x or greater. so I could do a: # CheckRpmVersion Somepackage-1.2.3 And would output: whether the package is installed or not and if it was equal to or greater than the version 1.2.3. I know I can pull out... (0 Replies)
Discussion started by: Ikon
0 Replies

4. Solaris

Solaris 10 ftp connection problem (connection refused, connection timed out)

Hi everyone, I am hoping anyone of you could help me in this weird problem we have in 1 of our Solaris 10 servers. Lately, we have been having some ftp problems in this server. Though it can ping any server within the network, it seems that it can only ftp to a select few. For most servers, the... (4 Replies)
Discussion started by: labdakos
4 Replies

5. Shell Programming and Scripting

testing a dhcp connection

Hi there, I have a computers that has a fixed address : terminal48:~# cat /etc/network/interfaces # This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). # The loopback network interface auto lo iface lo... (1 Reply)
Discussion started by: chebarbudo
1 Replies

6. Shell Programming and Scripting

Testing a comand in the script

Hi everyone , i am new to shell scripting and am having some problem to test if this line has been executed well and display a pass message on the screen or fail if not sqlplus XXTEST/$2 <<END > $XXTEST_TOP/log/$0.log @$XXTEST_TOP/admin/sql/XXTEST_SPE1_XX_QUOTE_DETAILS_TBL.sql XXTEST$2... (2 Replies)
Discussion started by: Lutchumaya
2 Replies

7. Shell Programming and Scripting

Testing telnet connections in a script

Hi, I am trying to figure out how to test to see if a server is accepting telnet connections via a script. I have several remote MPE servers that are set in single user mode (and hence not accepting telnet connections), for their backups, I want to try and automate a test (from a unix... (0 Replies)
Discussion started by: dikiee
0 Replies

8. Solaris

Testing physical network connection

How do you test the physical network connection of an interface in solaris. I know that if you have an active connection and the cable gets yanked, you can look in the messages file to check for link failure messages. But is there any better way to see if you have good layer 2 connectivity? (1 Reply)
Discussion started by: tjlst15
1 Replies

9. Shell Programming and Scripting

Testing VPN Connection

Hi All: I need a script that can be timed to run every half hour to an hour to run a traceroute through a VPN to test that a connection is still up from a Win XP system. Which would be the best, C++ or Perl and what are some good resources to look at. (If anyone has a script to do this... (1 Reply)
Discussion started by: maxhewitt
1 Replies

10. Shell Programming and Scripting

Testing ssh connection from KSH script

Hi. I have a kornshell script that runs on a daily basis as a cron job. Part of what the script does is copy the folder contents from another server to the current server (server where KSH script is running). I have a scp command, as follows: scp $REMOTE_HOST:$REMOTE_FILE_DIR/* $TMP_DIR ... (8 Replies)
Discussion started by: dmilks
8 Replies

Featured Tech Videos