title: Bash Script if a file exists and larger than loop
body: <p>*Note i edited this so my final functioning code is below</p>
  
  <p>Ok so I'm writing a bash script to backup our mysql database to a directory, delete the oldest backup if 10 exist, and output the results of the backup to a log so I can further create alerts if it fails.  Everything works great except the if loop to output the results, thanks again for the help guys code is below!</p>
  
  <pre><code>#! /bin/bash
  #THis creates a variable with the date stamp to add to the filename
  now=$(date +"%m_%d_%y")
  #This moves the bash shell to the directory of the backups
  cd /dbbkp/backups/
  #Counts the number of files in the direstory with the *.sql extension and deletes the oldest once 10 is reached.
  [[ $(ls -ltr *.sql | wc -l) -gt 10 ]] &amp;&amp; rm $(ls -ltr *.sql | awk 'NR==1{print $NF}')
  #Moves the bash shell to the mysql bin directory to run the backup script
  cd /opt/GroupLink/everything_HelpDesk/mysql/bin/
  #command to run and dump the mysql db to the directory
  ./mysqldump -u root -p dbname &gt; /dbbkp/backups/ehdbkp_$now.sql --protocol=socket --socket=/tmp/GLmysql.sock --password=password
  
  #Echo the results to the log file
  
  #Change back to the directory you created the backup in
  cd /dbbkp/backups/
  
  #If loop to check if the backup is proper size and if it exists
  if find ehdbkp_$now.sql -type f -size +51200c 2&gt;/dev/null | grep -q .; then 
  echo "The backup has run successfully" &gt;&gt; /var/log/backups
  else
  echo "The backup was unsuccessful" &gt;&gt; /var/log/backups
  fi
  </code></pre>