title: Running "su -c" in script as root
body: <p>I have been trying to automate a process of rsyncing many user directories from one host to another.  I have set up an SSH key pair so that the user can go straight from server A to server B without a password prompt.  The problem is that when I run the command as root, instead of it cycling through each user account and syncing only the data in that specific user directory it performs a sync from the root level directory of all of the users thus creating the root directory structure and all of the child directories inside each user directory!</p>
  
  <p>The command I am running is:</p>
  
  <p>(As root):</p>
  
  <pre><code>#!/bin/bash
  
  for user in $(&lt;/root/scripts/users.txt)
  do
    su - $user -c "chmod 600 .ssh/*;rsync -avvh --stats --delete --exclude ".*/" --exclude=".*" . remotehost:."
  done
  </code></pre>
  
  <p>If I run the command as root on the command line (i.e. su to the username and then perform the commands inside the quotes it works fine.  If I run the command as root and change the command inside the quotes to just ask for the path it should be it shows that users home directory so I am lost as to why this is not just changing to that specific user, syncing the data in that users home directory with the remote host and then moving on to the next user.</p>
  
  <p>Help!?!</p>