Welcome to the Auto Cleanup Script documentation. This script is designed to help you automatically clean up specified files within home directories on your server, specifically cPanel/WHM Servers, making it easier to manage and maintain your hosting environment. In this documentation, we will guide you through the installation process, customization options, and important notes to ensure smooth operation.
The Auto Cleanup Script offers the following key features:
- Automated Cleanup: The script automatically locates and deletes specified file types within home directories.
- Customization: You can customize the types of files to be deleted to suit your specific requirements.
- Scheduled Cleanup: The script is configured to run on a predefined schedule, ensuring regular and hassle-free cleanup.
- Flexibility: You can modify the cron job schedule or add new file types as needed.
Whether you're a hosting provider or an individual managing your server, the Auto Cleanup Script can help keep your server clean and efficient.
Before setting up the Auto Cleanup Script, please make sure to complete the following prerequisites:
- Install dos2unix: Ensure that the 'dos2unix' utility is installed on your server. This utility is required to convert script files to Unix format and make them executable. Otherwise, script won't execute.
- For CentOS/RHEL:
yum install dos2unix -y
apt-get install dos2unix
- Create a setup file:
- Add the following code to the file:
- Save and exit the file.
- Make the setup script executable:
- Run the setup script:
#!/bin/bash # Define the URL for the cleanup script CLEANUP_SCRIPT_URL="https://hostingspell.com/includes/public_scripts/acs/auto_cleanup_script.sh" # Define the cleanup script location CLEANUP_SCRIPT="/root/auto_cleanup_script.sh" # Download the cleanup script and make it executable wget -O "$CLEANUP_SCRIPT" "$CLEANUP_SCRIPT_URL" chmod +x "$CLEANUP_SCRIPT" # Add the cron job to run the cleanup script every Sunday at 3 AM (crontab -l ; echo "0 3 * * 0 $CLEANUP_SCRIPT") | crontab - # Display a message indicating the setup is complete echo "Auto Cleanup Script setup complete."
chmod +x auto_cleanup_install.sh
The script will download and set up the Auto Cleanup Script on your server.
- Now type the following command:
- For 'auto_cleanup_script.sh':
- This step ensures that the script files are compatible with Unix systems.
- At the end, script is now execuatble on each sunday 3AM.
- Enjoy the peacefull life!
The Auto Cleanup Script comes with a set of default file types that are scheduled for deletion within home directories. These default file types include:
- *.tar.gz: Tarball archives.
- *.wpress: WordPress backup files.
- error_log: Error log files.
By default, the Auto Cleanup Script is configured to run every Sunday at 3 AM. This ensures regular cleanup of the specified file types within home directories.
Before running the script, you can customize the types of files the script deletes within home directories. The script comes with a default set of file types, but you can add, delete, or update them to match your requirements. To customize the script:
- Open the Cleanup Script:
- Customize File Types: Locate the section in the script that defines the file types to be deleted. The section looks like this:
- Add, Delete, or Update File Types: You can perform the following actions:
# Define the file types you want to delete file_types=("*.tar.gz" "*.wpress" "error_log")
- Add File Types: To add a new file type for deletion, insert it into the array within double quotes and separate multiple file types with spaces. For example, to add ".log" files and ".zip" files:
file_types=("*.backup" "*.wpress" "error_log")
By customizing the file types, you can tailor the script to clean up specific types of files in your home directories.
Changing Cron Job Frequency
If you want to change the frequency at which the cleanup script runs automatically, follow these steps:
- Edit the Cron Tab:
- Modify the Cron Job Line: Locate the line that corresponds to the cleanup script. Modify this line to specify the desired schedule. For example, to run the script every day at 2 AM, use:
- Save the changes and exit the text editor.
0 2 * * * /root/auto_cleanup_script.sh
If you need to force the execution of the Auto Cleanup Script outside of its scheduled time (e.g., for immediate cleanup), you can do so manually. To force execution:
- Open your terminal or SSH into your server.
- Navigate to the location of the Auto Cleanup Script:
- Run the script:
- Note: It is highly recommended to run this script using the screen utility for uninterrupted execution.
Running the script manually will trigger an immediate cleanup, regardless of the scheduled time. Use this option with caution and only when necessary.
- Always ensure you have backups of important data before running the script or making changes.
- Review and test any changes to the cron job schedule to ensure they meet your requirements and do not disrupt your server's operation.
- Regular Backups: It's crucial to maintain regular backups of critical data. While this script aids in cleanup, having backups is essential for data recovery in case of accidental deletions.
- Script Testing: We recommend testing the script in a non-production environment first to ensure it behaves as expected and doesn't inadvertently delete important files.
- Script Updates: Keep an eye out for script updates or improvements in the future. You can find these updates and instructions on how to apply them [here].
- User Responsibility: You are responsible for any modifications or customizations you make to the script. Please follow best practices and ensure your changes align with your server's needs.
- Security: This script should only be used on servers where it's necessary, and we advise against running scripts from untrusted sources.
- Documentation: For comprehensive documentation and advanced customization options, refer to this page only.