|
Home > Archive > Unix Programming > September 2004 > Need code example to detect FTP server outage and do auto failover in unix shell scri
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Need code example to detect FTP server outage and do auto failover in unix shell scri
|
|
| Bryan Cummings 2004-09-02, 6:51 pm |
| I have a batch script writen in unix shell (csh) that pulls feed files
from a remote FTP server. If that FTP server is down (or the account
is locked), I would like to have the shell script be able to detect
this and do some other action (connect to a secondary FTP mirror and
send email warning).
If anyone has done this before or just has an idea of how to go about
doing this I would appreciate it.
Thanks in advance.
Sincerly
B
(A developer who gets stumped once in a while and isn't afraid to stop
and ask for directions... 
| |
| Jens.Toerring@physik.fu-berlin.de 2004-09-02, 6:51 pm |
| Bryan Cummings <Bryan.Cummings2@xerox.com> wrote:
> I have a batch script writen in unix shell (csh) that pulls feed files
> from a remote FTP server. If that FTP server is down (or the account
> is locked), I would like to have the shell script be able to detect
> this and do some other action (connect to a secondary FTP mirror and
> send email warning).
> If anyone has done this before or just has an idea of how to go about
> doing this I would appreciate it.
I would guess that the simplest method would be to install 'wget'
and use that. From its return value you can see if the download
succeeded or failed. So a csh equivalent of
wget ftp://ftp.server.com 2>&1
if [ $? ]; then
wget ftp://ftp.mirror.com 2>&1
fi
should already do the job.
Regards, Jens
--
\ Jens Thoms Toerring ___ Jens.Toerring@physik.fu-berlin.de
\__________________________ http://www.toerring.de
| |
| SM Ryan 2004-09-02, 6:51 pm |
| Bryan.Cummings2@xerox.com (Bryan Cummings) wrote:
# I have a batch script writen in unix shell (csh) that pulls feed files
# from a remote FTP server. If that FTP server is down (or the account
# is locked), I would like to have the shell script be able to detect
# this and do some other action (connect to a secondary FTP mirror and
# send email warning).
@ (telnet 10.10.10.41 21 </dev/null | grep Escape) 1>/dev/null 2>&1; echo $?
0
@ (telnet ftp.google.com 21 </dev/null | grep Escape) 1>/dev/null 2>&1; echo $?
1
That will at least tell you if you can connect. If you tclsh installed,
tclsh << ':eof'
if {[catch {socket "<---host-name-or-address-here--->" 21} c]} {
puts stderr fail
exit 1
}
fconfigure $c -translation crlf -buffering line
set user 0
while {[gets $c l]>=0} {
puts "$user $l"
if {!$user && [string match 2* $l]} {
puts $c "USER <---user-name-here--->"
set user 1
} elseif {[string match 3* $l]} {
puts $c "PASS <---password-here--->"
} elseif {$user && [string match 2* $l]} {
puts pass
exit 0
} elseif {[string match {[45]*} $l]} {
break
}
}
puts fail
exit 1
:eof
will verify host, user, and password.
--
SM Ryan http://www.rawbw.com/~wyrmwif/
A bunch of savages in this town.
|
|
|
|
|