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?
[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
[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
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 ?