Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I check if the server is down or any other connection errors while using LFTP and then email once such error has occurred.

did something this to make it work. Is this the correct/best approach.

lftp -e "bye" -u $USER,$PASS $HOST 2> abc.log

if [ ! -s abc.log ]; then
        echo "EMPTY"
        mailx < "Message"
        echo "NOT EMPTY"
share|improve this question
This may not answer your question directly but... use Pingdom or another service like it, they provide 5 free checks, it most certainly can do what you are trying to do with more options and features. This assumes the box is on the internet though. – Brent Pabst Dec 12 '12 at 21:27

The "best" approach is a real monitoring system that attempts to connect to the FTP server (Nagios, OpenNMS, InterMapper, etc.) -- or a third party remote solution (there are lots of those too).

There's a historical question with answers that basically list a whole bunch of tools which might be useful, and if you pick one that looks like it meets your needs we can probably help you with any questions you may have about implementation details.

Your solution is certainly "Good Enough" as a fast fix -- I would prefer to check the return status of lftp (see the man page for a list of possible return codes), but checking a log file is adequate too.
Two other suggestions to improve what you have:

  1. Remember to delete the log file, and check that it exists as part of your script
    If the log file doesn't exist something failed spectacularly, which is a different problem than the server being down.
  2. Parse the log and include that info in your message.
    Having the server be down is obviously a different problem than the username/password not working, and you probably want to handle it differently.
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.