Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to catch ftp errors in shell script

 
manoj r patil
Ranch Hand
Posts: 181
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Following is the extract of my shell script (bash) -

My problem is if for some reason, ftp could not logged in successfully, still my script goes ahead and executed the stuff. How can I stop my execution if there is any type of exception [saying login error, file not found, etc.]. Can anyone help me out please?>
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11865
194
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Expect scripting language was created for just such a purpose. The Wikipedia article on Expect even has an example (under "Below is an example that automates sftp") that handles timeouts before login. There is an example script at Sun that shows how to use FTP to log into different types of machines - e.g. if the prompts are different. (TCL / TK were a Sun product at the same time Java first came out, and Expect is built on TCL)

You can decide for yourself what to do if you do not login - do you simply stop, do you retry 'x' times, do you try a different box ...

TCL / TK / Expect are available every version of Linux (and most Unix systems I have worked with). Many Linux systems come with it pre-installed (especially if you have dial-up networking installed - many of the dial-up scripts are Expect scripts).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic