issue a ping on a remote box


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting issue a ping on a remote box
# 1  
Old 11-19-2008
issue a ping on a remote box

Hi there

I am running a script on a central box (boxA) that will send a remote request to boxB to perform a ping test to an ip

note: I am not pinging boxB from boxA but sending a request over ssh to get boxB to perform a ping test !

The thing is, I want the script back at boxA to know whether the remote ping was successful or not ...is this possible, i tried using this 'if' test condition hoping that a true/false would come back, am i doing something wrong?

Code:
[root@boxA] # vi test  

#!/bin/ksh -x

if [ `ssh boxB 'ping 172.1.1.1'` ]; then
echo "can ping from boxA"
else
echo "cant ping at all"
fi

NOTE: this ip is in fact definitely pingable from boxB but I get the following return from my script

Code:
[root@boxA] # ./test
+ FCEDIT=vi
+ export FCEDIT
+ set -o vi
+ + uname -n
PS1=boxA$ 
+ EDITOR=vi
+ export EDITOR
+ ssh boxB ping 172.1.1.1
+ [ 172.1.1.1 is alive ]
./test[5]: is: unknown test operator
+ echo cant ping at all
cant ping at all

As you can see from the bit highlighted in red above, the remote ping seems to be working, but how do I get my local script on boxA to be made aware of this

Any help on this would be greatly appreciated
# 2  
Old 11-19-2008
if [ "`ssh boxB 'ping 172.1.1.1'`" ]; then....

The problem is that when using ` xxx ` you will substitue that with the return of the command...

so when this is executed your code will look like this:

if [ 172.1.1.1 is alive ] then..

you need to use " " around that since if will see this as multiple args and doesnt know what do with it.

Hope this helps
# 3  
Old 11-19-2008
ah, thankyou very much, however (something I should have probably mentioned at the start ) I will actually be passing an argument to script, ie ill be running

./test 172.1.1.1

so therefore the code will have to be

f [ "`ssh boxB 'ping $1'`" ]; then ....

by me doing this, the solution you provided doesnt work, although it works perfectly with the original example i gave ...apologies for not stating this at the beginning

Ive tried shifting the three different quote characters around to no avail ....can you see any way I can get this to work using a $1 rather that putting the actual IP in the command ?
# 4  
Old 11-19-2008
Why not try assigning your check result to a variable like:
Code:
check=`ssh boxB "ping -s 1 -w 1 -c 1 $1" > /dev/null; echo $?`
if [ "$check" -eq "0" ]; then 
echo "ping successful!"
else
echo "can't ping!"
fi

That's just to simplify things.. at least for me.
# 5  
Old 11-19-2008
thanks, i found another way too


from boxA

Code:
#!/bin/ksh

ssh boxB "ping $1 2 > /dev/null 2>&1"

if [ $? -eq 0 ]; then
echo "can ping"
else
echo "cant ping at all"
fi


thankyou all for your responses
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. BSD

Ping remote sever, nc, telnet, whatever

I put this thread to shell and bsd, because I want to resolve this matter on bsd. May somebody can explain to me how to ping a remote server, in unix. BTW the following code examples were tried on a linux system as well, with the same output, nothing. But on my bsd are not installed nmap neither... (4 Replies)
Discussion started by: 1in10
4 Replies

2. Shell Programming and Scripting

Notify when the script run(hourly)on my jump-box only when there is a failure on my remote-box

Team, Presently I have a script, which i have set up cron on one of my Jump-boxes,and gives me the output on every hourly basis,fetching the data from the remote machine.Basically it gives me the list of all active users logged and its count once we execute the script.Here the count is... (6 Replies)
Discussion started by: whizkidash
6 Replies

3. AIX

Ping to remote host failed

Actually. I was getting a ping to remote host failed for one of my etherchannel. When I checked it was in backup adapter and again I use to faileover and brought to primary channel. But it was again going to backup channel and giving me the alert ping to remotehost failed. When I checked the load... (3 Replies)
Discussion started by: Mohamed Thamim
3 Replies

4. Red Hat

Can't ping my unix box by name

Hi All, I have recently setup a Windows 2003 server as AD / Domain Controller. In it, I have a VMWare for RHEL 4. I have 3 other computers connected to the network all using Windows 7. These computers can ping each other by name. But none of these can ping the Unix OS in the VMWare of the... (5 Replies)
Discussion started by: adshocker
5 Replies

5. Linux

How to find remote Linux box login account without login in to that box?

Hi, How to find remote Linux box login account without login in to that box? I don't have login account at my remote Linux box. But I need who are all having login account. How do I findout? Thanks, --Muthu. (3 Replies)
Discussion started by: Muthuselvan
3 Replies

6. Shell Programming and Scripting

Help with Ping command for windows Box

Hi, I would like to write a script for checking the windows remote server has responding or not from Unix box. 123.34.56.222-- the windows remote server I wrote like: ping 123.34.56.222 PING 123.34.56.222: 64 byte packets 64 bytes from 123.34.56.222: icmp_seq=0. time=8. ms 64... (1 Reply)
Discussion started by: koti_rama
1 Replies

7. Linux

Can't SSH / ping Linux box !!!

I have a linux box build11 which can be pinged from build18 (Windows) box. And we can only login to the box (using SSH) from build18 box. Plz help to characterize the problem, network, DNS, DHCP, etc (or whatever which I am unsure) Any idea what may be the reason ? :confused: Thanks in... (4 Replies)
Discussion started by: csaha
4 Replies

8. Programming

cathcing `mozilla -remote ping()` within c++

Here is my problem. An extension and alternative to my initial post https://www.unix.com/showthread.php?t=18043 This is what I have done so far to counter it. In my application, I have used /usr/bin/mozilla -remote "openURL(URL)" The -remote makes sure that I go and open the URL in an... (1 Reply)
Discussion started by: vino
1 Replies

9. SCO

Openserver 5.0.4 can't be ping or telnet into from a remote site

Hi, Can anybody help me out why l can't not ping my server with Openserver 5.0.4 with my windows machine from a remote site. The machine could see the local LAN with the Router however, i can't ping or telnet unto the server from another site on the WAN. The default gateway was configure on the... (0 Replies)
Discussion started by: kayode
0 Replies

10. Cybersecurity

securing a remote box

someone has access to my server... I've got a solaris 7 box with remote access only. many of the services don't have passwords and someone recently messed with the shadow file -the root: line was changed: . password field was changed to NP . the number after that was changed too The... (8 Replies)
Discussion started by: sphiengollie
8 Replies
Login or Register to Ask a Question