Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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"
else
        mailx abc@xyz.com < "Message"
        echo "NOT EMPTY"
fi
share|improve this question
1  
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

1 Answer 1

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

 
discard

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.