Need help with error checking

I am creating a script that will automatically use sftp to connect to a site and download a file, extract the tar and then delete the tar file once completed.

What I am stuck on is the error checking for this process.

Here is the code so far:

Now this works for me as is, but i need error checking for 2 points.

1 for the ftp connection to wait 2 minutes and retry if there is no connection and to spawn off a yellow warning message to an email address at 10 minutes and a red warning message at 20. After 20 minutes the script dies.

The second message which i may or may not need, is one to monitor the tar output for any error messages. This is not as important as the first one however.

Any suggestions or help will be appreciated!

Thank you