Testing connection with a script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Testing connection with a script
# 8  
Old 09-08-2009
Modify your script something like this :
Code:
until grep 0 /home/sipp/A > /dev/null
do

[a command]

## Added here one again the ping statement to test the connection 
ping hostB -c3 -W3 > /dev/null
echo $? > A
if grep 0 /home/sipp/A > /dev/null
then exit;
fi 

done

# 9  
Old 09-09-2009
Allmost there..

I came up with this:
(instead of starting dhcpd I am testing with mahjongg)

It goes like this:
when there is no connection the script will start mahjongg
when the connection come up again mahjongg gets killed
that part works fine.
But when the connection is ok, the script tryes to kill a process that is not there.. it is supposed to exit. Can anyone with a sharp eye see where my error is?

Regards KimJensen

A=`ps auxww |grep /usr/games/mahjongg|grep -v grep |awk '{print $2}'` > /dev/null #process ID of mahjongg

ping 10.0.0.2 -c3 -W3 > /dev/null

if [[ $? -eq 1 && -z $A ]] #if connection error and mahjongg pid is empty
then /usr/games/mahjongg & #then start mahjongg
elif
[[ $? -eq 0 && -z $A ]] # if connection ok and mahjongg pid is empty
then exit #do nothing
else kill $A # else kill mahjongg pid
fi

---------- Post updated at 12:49 PM ---------- Previous update was at 08:47 AM ----------

I solved it like this:
#!/bin/bash
A=`ps auxww |grep /usr/games/mahjongg|grep -v grep|awk '{print $2}'`
ping 10.0.0.2 -c3 -W3 > /dev/null
B=$?
if [[ $B -eq 1 && -z $A ]]
then /usr/games/mahjongg &
elif
[[ $B -eq 1 && -n $A ]]
then exit
elif
[[ $B -eq 0 && -z $A ]]
then exit
else kill $A
fi

-not very pretty but it works Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

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
Login or Register to Ask a Question