This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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?>
love your job and not your company;
...because you never know when your company will stop loving you!
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).