• 🏠 Accueil
  • 🧰 Générateurs
  • 📰 Blog
  • 🔎 Rechercher
  • 📧 Contact
  • 📘 Livre d'or
  • 🗞️ News
  • 💰 Soutien
  • ℹ️ Info : Le site a été modernisé pour être plus lisible et compatible avec les smartphones. N'hésitez pas à me signaler tout bug via le formulaire de contact.

    Description

    This script will remove old unwanted files on the server directories. You can add many steps, for all the different directories, or retention dates

    purge_old_files.sh

    #!/bin/bash 
    ########################################## 
    # File: purge_old_files.sh               # 
    # Author: Jerome DESMOULINS              # 
    # Date: 2010/01/12 - Original version    # 
    ########################################## 
    # This script remove old files from      # 
    # listed directories                     # 
    ########################################## 
    # Updates:                               # 
    #    2011/04/13: Separate files and dir  # 
    #      for /tmp (change for two steps)   # 
    ########################################## 
    ### Initialisation for environnement variables mandatory for DjeShellSteps ### 
    . `dirname $0`/djeshellsteps.sh 
    ### Beginning of Shell Script ### 
    BeginSteps 
    echo "Starting Shell Script..." 
    ### Step 10 ### 
    Step 10 "Removing exploitation old log files" 
    if [ $RunThisStep -eq 1 ]; then 
      cd $LogDir 
      find . -mtime +45 -type f -exec ls {} ; 
      find . -mtime +45 -type f -exec rm {} ; 
    fi 
    ### Step 20 ### 
    Step 20 "Removing /tmp old files" 
    if [ $RunThisStep -eq 1 ]; then 
      cd /tmp 
      find . -mtime +7 -type f -exec ls {} ; 
      find . -mtime +7 -type f -exec rm -f {} ; 
    fi 
    ### Step 30 ### 
    Step 30 "Removing /tmp old directories" 
    if [ $RunThisStep -eq 1 ]; then 
      cd /tmp 
      find . -mtime +7 -type f -exec ls {} ; 
      find . -mtime +7 -type f -exec rm -f {} ; 
    fi 
    ### End of Shell Script ### 
    EndSteps 

    Retour



    (c) 2005-2025 Jérôme DESMOULINS
    Mentions légales