title: best way to programmatically check for a failed scp in a shell script
body: <p>I have a shell script that I'm working on with this line of code that does a loop through local files (.gz) and does an scp. I want to test for a failed <code>scp</code> if possible. I am doing a loop so I can echo each file name to a log so I can keep track of it.</p>
  
  <p>Can someone show me how to check for failed scp? or better yet, a good code example to do this?  Thanks for your help.</p>
  
  <pre><code>for gzfile in $LOCALDMPDIR/*.gz
  do
    /usr/bin/scp -P 2222 -i $KEYFILE $gzfile foobar@$1:$TGTDIR
    echo "$gzfile is done. " 2&gt;&amp;1
  done
  </code></pre>