title: Resource temporarily unavailable error in Bash script using scp
body: <p>To avoid installing <code>inotifywait</code> or <code>incron</code>, I've created a simple bash script to copy a file to a server whenever it changes using <code>scp</code> on Ubuntu 12.04:</p>
  
  <pre><code>FILE=filename.log
  while true
  do
      STDOUT=$(ls -l $FILE)
      [ "$STDOUT_OLD" != "$STDOUT" ] &amp;&amp; STDOUT_OLD=$STDOUT &amp;&amp; \
       scp -v $FILE hostname.com:/home/user/path/
      sleep 5
  done
  </code></pre>
  
  <p>When I run it, it copies the file immediately, but subsequent changes to the file yields this error:</p>
  
  <pre><code>...
  filename.log: Resource temporarily unavailable
  Sink: scp: filename.log: Resource temporarily unavailable
  ...
  </code></pre>
  
  <p>I got the same error using a conventional <code>if</code> block:</p>
  
  <pre><code>if [ "$STDOUT_OLD" != "$STDOUT" ]
  then
      STDOUT_OLD=$STDOUT
      scp -v $FILE hostname.com:/home/user/path/
  fi
  </code></pre>
  
  <p>What's happening, and how can I fix it? Thanks!</p>