title: Bash script to cleanup Linux server session folder
body: <p>I'm managing a Plesk Linux webserver with multiple website-subscriptions that all run in FastCGI. The setup requires me to have a session folder for each subscription (PHP writes session data to that folder). The problem is that over time, these session folders get full and are not automatically cleared.</p>
  
  <p>My hosting provider therefore created the following script, that would run weekly in a cron job.</p>
  
  <pre><code>#!/bin/bash
  
  mapfile -t domains &lt; /home/cmadmin/domains
  
  for i in "${domains[@]}"
  do
   #echo "Deleting $i Session folder content"
   find /var/www/vhosts/$i/session/* -mtime +7 -type f -delete
  done
  </code></pre>
  
  <p>The objective of the script is to loop over each subscription on my server, to go into the specific session folder for that subscription and there to remove all files older than 7 days.</p>
  
  <p>This script seems to work fine, but for some reason, when it reaches the subscription called <code>groepsmanager-rspo.com</code> everything inside that folder gets deleted. So even files outside the session folder, like <code>/var/www/hosts/groepsmanager-rspo.com/httpdocs/</code> and <code>/var/www/hosts/groepsmanager-rspo.com/logs</code> are deleted.</p>
  
  <p>The very strange thing is that all other subscriptions are completely fine. Upon investigating their contents, indeed only files younger than 7 days remain. </p>
  
  <p>At first we thought the dash (-) in the folder name might cause problems, but this is not the case, since other folder names with a dash are fine. Also, there are no files called <code>session</code> in folders outside the global session folder.</p>
  
  <p>Does anyone have a clue why this particular subscription keeps getting removed? Are there any do's or dont's to keep in mind?</p>
  
  <p>Thanks in advance.</p>