title: Check the status code of a scp command and if it is failed, then call scp on another machine
body: <p>Below is my snippet of shell script in which I am executing scp command to copy the files from <code>machineB</code> to <code>machineA</code>.</p>
  
  <pre><code>for element in ${x[$key]}; do   # no quotes here
      printf "%s\t%s\n" "$key" "$element"
      if [ $key -eq 0 ]
      then
          scp david@machineB:/data/be_t1_snapshot/20131215/t1_$element_5.data /data01/primary/.
      fi    
  done
  </code></pre>
  
  <p>I have a very simple question which is mentioned below - </p>
  
  <p>If the above scp command in my shell script gives me this error for whatever reason -  <code>No such file or directory</code>
  then I need to try doing <code>scp</code> from <code>machineC</code> and for that scp command will be like this, only machine will be different and everything else will be same - </p>
  
  <pre><code>scp david@machineC:/data/be_t1_snapshot/20131215/t1_$element_5.data /data01/primary/.
  </code></pre>
  
  <p>So my question is how to check the output of the above scp command in my shell script and then decide whether I need to call scp command from machineC or not? Is there any status kind of thing which I can use to check and if it got failed for whatever reason, then I can call scp command on machineC?</p>
  
  <p>Is this possible to do in shell script?</p>