Having issues getting cron job to work

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,260
463
The referenced script is intended for users with root access to their system. You could remove the "/scripts/generate_maildirsize " line and create it via SSH, and then add it as a cron job using the "Cron Jobs" option in the cPanel interface of the account. You may need to consult with your hosting provider to see if SSH access is allowed.

Thank you.
 

mesut85u2

Member
Mar 21, 2015
9
1
1
Turkey
cPanel Access Level
Website Owner
Hi Kelvin,

I had problems with the cron as the usage quota for mailbox wasn't being updated. My support ticket with cPanel resulted in the following bash script. You can call it anything you like, but it needs to be saved with a sh extention. Mine is clearmail.sh

Code:
#!/bin/bash
# remove mail from [email protected] email account.
find /home/exampled/mail/exampledomain.com/info/ -type d \( -name cur -o -name new \) -exec find {} -type f -delete \;
# regenerate maildirsize (to update quota)
/scripts/generate_maildirsize --confirm exampled
This worked well when tested, and the usage quota of mailbox would be updated to zero MB each time.

You would just set a cron job to run this script to the frequency you require.

Hope this helps. :)
hi,

how can i call clearmail.sh file ?
 

magicalwonders

Well-Known Member
Nov 21, 2012
112
2
18
cPanel Access Level
Root Administrator
hi,

how can i call clearmail.sh file ?
You need to login to your server as root and type: crontab -e

That will open roots crontab entries in an editor.

You will want to read the man page on crontab to help you set it up. A copy of that page can be found here: unixhelp.ed.ac.uk/CGI/man-cgi?crontab+5 But basically it will look something like this:

0 2 * * * /root/clearmail.sh 2>&1

This will run the script at 2 AM every day.

Then you can save the text file and the new cron will be installed (providing there are no errors).
 
Last edited by a moderator:

komloscs

Registered
Mar 22, 2016
1
0
1
Budapest
cPanel Access Level
Website Owner
Hi Kelvin,

I had problems with the cron as the usage quota for mailbox wasn't being updated. My support ticket with cPanel resulted in the following bash script. You can call it anything you like, but it needs to be saved with a sh extention. Mine is clearmail.sh

Code:
#!/bin/bash
# remove mail from [email protected] email account.
find /home/exampled/mail/exampledomain.com/info/ -type d \( -name cur -o -name new \) -exec find {} -type f -delete \;
# regenerate maildirsize (to update quota)
/scripts/generate_maildirsize --confirm exampled
This worked well when tested, and the usage quota of mailbox would be updated to zero MB each time.

You would just set a cron job to run this script to the frequency you require.

Hope this helps. :)

You can do it without ssh, using only one line cron, that you can set up in cpanel:

You need to add this to the end of the line in the example:

Code:
 -o -name maildirsize -delete
So the whole line looks like:

Code:
find /home/exampled/mail/exampledomain.com/info/ -type d \( -name cur -o -name new \) -exec find {} -type f -delete \; -o -name maildirsize -delete
Enjoy