title: Host key verification failed [rsync: connection unexpectedly closed]
body: <p>I'm stuck with a peculiar problem, where rsync command is not running when it is executed through crontab.<br>
  Below is the code :</p>
  
  <pre><code>#!/bin/sh -x
  PATH=/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/mysql/bin:/opt/android-sdk-linux/tools:/opt/android-sdk-linux/platform-tools:~/usr/lib/jvm/jdk-6/bin
  /bin/sh /etc/profile
  MyUSER="root"       # USERNAME
  MyPASS="password"         # PASSWORD
  MyHOST="localhost"  # Hostname
  Password="" #Linux Password
  
  MYSQL="$(which mysql)"
  if [ -z "$MYSQL" ]; then
  echo "Error: MYSQL not found"
  exit 1
  fi
  MYSQLADMIN="$(which mysqladmin)"
  if [ -z "$MYSQLADMIN" ]; then
      echo "Error: MYSQLADMIN not found"
      exit 1
  fi
  CHOWN="$(which chown)"
  if [ -z "$CHOWN" ]; then
      echo "Error: CHOWN not found"
      exit 1
  fi
  CHMOD="$(which chmod)"
  if [ -z "$CHMOD" ]; then
      echo "Error: CHMOD not found"
      exit 1
  fi
  
  GZIP="$(which gzip)"
  if [ -z "$GZIP" ]; then
      echo "Error: GZIP not found"
      exit 1
  fi
  CP="$(which cp)"
  if [ -z "$CP" ]; then
      echo "Error: CP not found"
      exit 1
  fi
  MV="$(which mv)"
  if [ -z "$MV" ]; then
      echo "Error: MV not found"
      exit 1
  fi
  RM="$(which rm)"
  if [ -z "$RM" ]; then
      echo "Error: RM not found"
      exit 1
  fi
  RSYNC="$(which rsync)"
  if [ -z "$RSYNC" ]; then
      echo "Error: RSYNC not found"
      exit 1
  fi
  
  MYSQLBINLOG="$(which mysqlbinlog)"
  if [ -z "$MYSQLBINLOG" ]; then
      echo "Error: MYSQLBINLOG not found"
      exit 1
  fi
  # Get data in dd-mm-yyyy format
  NOW="$(date +"%d-%m-%Y-%T")"
  
  DEST="/home/db-backup"
  mkdir $DEST/Increment_backup.$NOW
  LATEST=$DEST/Increment_backup.$NOW
  $MYSQLADMIN -u$MyUSER -p$MyPASS flush-logs
  newestlog=`ls -d /usr/local/mysql/data/mysql-bin.?????? | sed 's/^.*\.//' | sort -g | tail -n 1`
  echo $newestlog
  for file in `ls /usr/local/mysql/data/mysql-bin.??????`
  do
          if [ "/usr/local/mysql/data/mysql-bin.$newestlog" != "$file" ]; then
       echo $file
       echo $Password | sudo -S $CHMOD 0777 $file
           #sudo $MYSQLBINLOG $file&gt;$file.$NOW.sql
       $CP "$file" $LATEST
       #$RM "$file.$NOW.sql"
       #$MV $file.sql.gz /$LATEST
          fi
  done
  for file1 in `ls $LATEST/mysql-bin.??????`
  do
   $MYSQLBINLOG $file1&gt;$file1.$NOW.sql 
   $GZIP -9 "$file1.$NOW.sql"     
   $RM "$file1"
  done
   $RSYNC -v -e ssh $LATEST abc@192.168.1.9:/home/rsync-backup/
  #FILE=$LATEST/"mysql-bin.??????"
  #$MYSQLBINLOG $FILE&gt;$FILE.$NOW.sql
  #$GZIP -f "$FILE.$NOW.sql"
  pwd
  </code></pre>
  
  <p>Rsync happens when the code is run manually, but fails when it is run through crontab. Rest of the commands are working fine. From the logs I got this information:</p>
  
  <pre><code>Host key verification failed.^M
  rsync: connection unexpectedly closed (0 bytes received so far) [sender]
  rsync error: unexplained error (code 255) at io.c(600) [sender=3.0.6]
  </code></pre>