Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

Custom Cleanup Script

Discussion in 'Workarounds and Optimization' started by Bashed, Oct 24, 2017.

  1. Bashed

    Bashed Well-Known Member

    Joined:
    Dec 18, 2013
    Messages:
    113
    Likes Received:
    3
    Trophy Points:
    18
    cPanel Access Level:
    Root Administrator
    Hello,

    I run the below manually on occasion to do cleanup on my servers. I'd like to automatic this via cron into one single bash script. Would anyone know how to go about this? I've never done that before.

    Code:
    exim -bp | grep \< | awk '{print $3}' | xargs exim -Mrm
    find /home -type f -name error_log -delete
    for user in `/bin/ls -A /var/cpanel/users` ; do rm -fv /home/$user/backup-*$user.tar.gz ; done
    updatedb
    locate .pureftpd-upload | xargs rm -fv
    locate -r /core\.[0-9] | grep /home | egrep -v 'virtfs|php|sql|ini'
    rm -rf /usr/local/apache.backup*
    rm -fv /home/*/tmp/Cpanel_*
    rm -f /var/log/*.gz
    rm -f /var/log/exim_mainlog-*
    rm -f /var/log/exim_paniclog-*
    rm -f /var/log/exim_rejectlog-*
    rm -f /var/log/lve-stats.log-*
    rm /home/*.tar.gz -fv
    rm /home/*/public_html/error_log -fv
    rm /home/*/public_html/*/error_log -fv
    rm /home/*/public_html/*/*/error_log -fv
    rm /home/*/public_html/*/*/*/error_log -fv
    rm /home/*/public_html/*/*/*/*/error_log -fv
    cd /var/log
    rm -f cagefs.log-* cron-* maillog-* messages-* secure-* spooler-* up2date-* *.gz
    yum clean all
    
    grep cwd /var/log/exim_mainlog | grep -v /var/spool | awk -F"cwd=" '{print $2}' | awk '{print $1}' | sort | uniq -c | sort -n
    mysqlcheck --auto-repair --optimize --all-databases
    
    
    **********************
    
    MAIL SCRIPT CLEANUP
    
    **********************
    
    nano /root/delete_all_junk.sh
    
        #!/bin/bash
        MAILDIRS=$(find /home/*/mail/*/* -maxdepth 0 -type d)
        INBOXFOLDERS=(.Trash .Junk .Spam .Low\ Priority .cPanel\ Reports)
        for basedir in $MAILDIRS; do
        for ((i = 0; i < ${#INBOXFOLDERS[*]}; i++)); do
        for dir in cur new; do
        [ -e "$basedir/${INBOXFOLDERS[$i]}/$dir" ] && (
        echo "Processing $basedir/${INBOXFOLDERS[$i]}/$dir..."
        find "$basedir/${INBOXFOLDERS[$i]}/$dir/" -type f -mtime +30 -delete
        )
        done
        done
        done
        /scripts/generate_maildirsize -verbose -allaccounts -force -confirm
    
    chmod +x /root/delete_all_junk.sh
    sh /root/delete_all_junk.sh
     
    cesarlopes likes this.
  2. cesarlopes

    cesarlopes Registered

    Joined:
    Oct 18, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    51
    Location:
    Tiete, Sao Paulo, Brazil
    cPanel Access Level:
    Reseller Owner
    I liked your script ...

    If you create a shell file you can run it with cron, have you tried this?
     
  3. Bashed

    Bashed Well-Known Member

    Joined:
    Dec 18, 2013
    Messages:
    113
    Likes Received:
    3
    Trophy Points:
    18
    cPanel Access Level:
    Root Administrator
    Ok, did you actually read my post at all? It's not a "script". I specifically asked how to put all the commands into a script and run it automatically via cron. You completely ignored the very same point I asked about.
     
  4. cPanelMichael

    cPanelMichael Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    44,803
    Likes Received:
    1,898
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    Hello,

    Let us know if the previous post helped. Note that you will typically find better support for bash scripting on websites such as StackOverflow.

    Thank you.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. Bashed

    Bashed Well-Known Member

    Joined:
    Dec 18, 2013
    Messages:
    113
    Likes Received:
    3
    Trophy Points:
    18
    cPanel Access Level:
    Root Administrator
    Thanks, but link is invalid. Can you just paste the code here?
     
  6. cPanelMichael

    cPanelMichael Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    44,803
    Likes Received:
    1,898
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    Hello @Bashed,

    I've removed the post you are referencing because the URL no longer works. If you're looking for help on how to create a bash script, you'll likely find more information on a website such as StackOverflow where programming discussing occur. Here's a third-party URL you may find helpful:

    How to Create a Simple Shell Script on Linux

    Thank you.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice