title: Bash Script to run a backup and upload to AWS S3 Failing
body: <p>Here's the code:</p>
  
  <pre><code>#!/bin/bash
  
  # -------------------------------------------------
  # -------------------------------------------------
  # Use a comma-delimited list of single-quoted
  # strings of the usernames to batch
  # if it's empty it will backup all user directories
  # in /home
  # -------------------------------------------------
  # -------------------------------------------------
  USER_ACCOUNT=();
  
  # -------------------------------------------------
  # -------------------------------------------------
  # Make sure the aws script is installed on the
  # server, and the bucket name to upload these too
  # are exact... case-sensitive
  # -------------------------------------------------
  # -------------------------------------------------
  S3BUCKET='Kevs-Bucket/Test';
  
  # Loop through the user array
  # If it's empty, then get all users in the /home 
  # directory, based on each folder
  # do not include root user
  if [ ${#USER_ACCOUNT[@]} -eq 0 ]; then
  # turn off dotglob and nullglob
  cd /home;
  shopt -s dotglob;
  shopt -s nullglob;
  DIRARR=(*/);
  # we have our directories, now loop them and grab the user
  # once we have the user, skip the root user
  for d in ${!DIRARR[@]}; do
      # Assign an account variable
      ACCT=stat -c '%U' ${DIRARR[$i]}; #NOT WORKING HERE
      if [ "$ACCT" == "root" ]; then
          echo "ROOT";
      else
          run_backup $ACCT $S3BUCKET;
      fi;
  done;
  else
  # we have our list, now loop through them all
  for i in ${!USER_ACCOUNT[@]}; do
      # Assign an account variable
      ACCT=${USER_ACCOUNT[$i]};
      run_backup $ACCT $S3BUCKET;
  done;
  fi;
  
  # -------------------------------------------------
  # -------------------------------------------------
  # Run the actual backup
  run_backup(){
  LOGFILE=/batch-move.log
  # Package the account
  ./scripts/pkgacct $1;
  echo '##########################################' &gt;&gt; $LOGFILE;
  echo "# Start: date +'%T'" &gt;&gt; $LOGFILE;
  echo "# Backing Up: $1" &gt;&gt; $LOGFILE;
  echo '##########################################' &gt;&gt; $LOGFILE;
  # Upload it to S3
  s3put $2/cpmove-$1.tar.gz  /home/cpmove-$1.tar.gz;
  echo '##########################################' &gt;&gt; $LOGFILE;
  echo "# Uploading Backup: $1" &gt;&gt; $LOGFILE;
  echo '##########################################' &gt;&gt; $LOGFILE;
  # Remove the file from the server
  /bin/rm -f /home/cpmove-$1.tar.gz;
  echo '##########################################' &gt;&gt; $LOGFILE;
  echo "# Removing Backup Up: $1" &gt;&gt; $LOGFILE;
  echo "# Finish: date +'%T'" &gt;&gt; $LOGFILE;
  echo '##########################################' &gt;&gt; $LOGFILE;
  }
  </code></pre>
  
  <p>I'm getting an error here <code>ACCT=stat -c '%U' ${DIRARR[$i]}; #NOT WORKING HERE</code> and the error is stating that -c is not a valid option for stat on my CentOS server</p>
  
  <p>I have verified through other means that <code>stat -c</code> does work, so I assume that my code attempting to get the folders owner into a variable is incorrect.</p>
  
  <p>Can you help me figure it out? </p>