Results 1 to 4 of 4
I have a process that does a ping to a server before it transmits backup data.
This tells me if the server is up or down.
I know that if ...
- 07-16-2009 #1Linux Newbie
- Join Date
- Jun 2006
- Posts
- 139
a question on return codes
I have a process that does a ping to a server before it transmits backup data.
This tells me if the server is up or down.
I know that if I code something and it is good I get a 0 and if bad I get a 1.
Now for my question:
The ping is going to return something either good responses(response times) or a response that it timed out.
Is there a way that if the ping returns with times(good) then the ftp world start and if it fails then the ftp would not proceed.
Any ideas
thanks
mace
- 07-16-2009 #2Linux Newbie
- Join Date
- Mar 2009
- Posts
- 228
Try this:
Code:ping -c 1 <IP_address> if [ $? -eq 0 ] then ftp <whatever...> else echo "Server did no respond" fi
- 07-17-2009 #3
I think that lomcevak has misunderstood.
So you are saying that you will get some specific exit code if it is bad, and anything else means it is good. In that case, basically do the opposite of what he said:
Does this make sense?Code:ping IP_ADDRESS ping_return=$? if [ "$ping_return" -neq "$bad_return" ]; then # do your FTP stuff else # ping returned bad response fiDISTRO=Arch
Registered Linux User #388732
- 07-17-2009 #4Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
So I think lomcevak's response is correct -- "0" is OK in scripting. Other values are not standardized, and there are at least 2 non-zero exit codes from ping. The deadline or timeout may be useful to specify, for example:If ping does not receive any reply packets at all it will exit with
code 1. If a packet count and deadline are both specified, and fewer
than count packets are received by the time the deadline has arrived,
it will also exit with code 1. On other error it exits with code 2.
Otherwise it exits with code 0. This makes it possible to use the exit
code to see if a host is alive or not.
-- excerpt from man ping
returns with exit code 1 after 1 second. Otherwise, the default seems to be 10 seconds.Code:ping -c 1 -W 1 microsoft.com
You may wish to discard the ping printable output, but that's something you can do once you get your code running correctly ... cheers, drlWelcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )


Reply With Quote