The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Having issues getting cron job to work

Discussion in 'E-mail Discussions' started by Tipiford, Feb 6, 2014.

  1. Tipiford

    Tipiford Member

    Joined:
    Feb 5, 2014
    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Website Owner
    Using the following command line:

    find /home/{PW}/mail/DOMAIN.com/.donotreply/inbox -type f -mtime +5 -exec rm {} \;

    (Have tried this with and without the period found in the site's email address, and with and without the password in curly brackets.)

    I am neither getting results, nor am getting an email saying the job completed or failed; nor do I see any cron jobs that I've added anywhere in the FTP.
     
  2. vanessa

    vanessa Well-Known Member
    PartnerNOC

    Joined:
    Sep 26, 2006
    Messages:
    817
    Likes Received:
    22
    Trophy Points:
    18
    Location:
    Virginia Beach, VA
    cPanel Access Level:
    DataCenter Provider
    First of all, do you have an email address set to receive cron output? You should see this in cPanel or in /var/spool/cron/$user on the MAILTO line. If you tacked a /dev/null to the end of the command, you're not going to see anything.

    Side question - any reason you don't dump this command into a script, and call the script via cron instead? It's not typically best practice to put commands like this directly into the crontab.
     
  3. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,854
    Likes Received:
    676
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    A password is not used in a path to a file/directory. You would enter the username of the account instead.

    Thank you.
     
  4. Tipiford

    Tipiford Member

    Joined:
    Feb 5, 2014
    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Website Owner
    Would the username be in curly brackets? Or just the username between slashes?
     
  5. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,854
    Likes Received:
    676
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    You would enter the username the same way you enter the rest of the path. EX:

    Code:
    /home/username/public_html/path/to/file
    Note that I did not review the rest of your cron job, so it's not an endorsement of how you are using the "rm" command. Instead, it's just to note that using the password in the path is the wrong way of doing it.

    Thank you.
     
  6. Tipiford

    Tipiford Member

    Joined:
    Feb 5, 2014
    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Website Owner
    Would you kindly review my code, as it is not working as is (and the path I copied and pasted from the FTP address bar, so I should think it to be correct):

    find /home/mail/DOMAIN.com/donotreply/.donotreply -name "*" -mtime +5 -exec rm {} \;

    (I have tried this with the dot preceding the "hidden" email address folder and without, still no joy.)

    Thanx
     
  7. vanessa

    vanessa Well-Known Member
    PartnerNOC

    Joined:
    Sep 26, 2006
    Messages:
    817
    Likes Received:
    22
    Trophy Points:
    18
    Location:
    Virginia Beach, VA
    cPanel Access Level:
    DataCenter Provider
    Try this one:


    Code:
    find /home/mail/DOMAIN.com/donotreply/.donotreply -name  "\*.\*" -mtime +5 -exec rm {} \;

    I recreated your directory structure and the above command appears to work as desired.
     
  8. Tipiford

    Tipiford Member

    Joined:
    Feb 5, 2014
    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Website Owner
    Thanx for the more explicit direction, however still no joy. I gave thought to a possible permissions issue, but looking at permissions, folders are set at 0751 (except for "cur" folder, which was at 0700 which I changed to 0751, and then back to 0700 when it didn't make a difference), which as I understand it, the account holder, is the the 7, which gives read/write/execute permission. I've looked in cPanel's File Manager, and can see the emails in the folder I'm trying to empty, but I see two folders with those emails in them, but making a change in permissions of either of the folders (experimenting to see if the folders were interconnected) changes both folders. Could the duplicate folders have anything to do with this problem? The two paths concerned are, and here is the code I've used for each:

    find /home/mail/.donotreply@DOMAIN_com/cur -name "\*.\*" -mtime +5 -exec rm {} \;

    find /home/mail/DOMAIN.com/donotreply/cur -name "\*.\*" -mtime +5 -exec rm {} \;

    Thanx for giving this your attention.
     
  9. Tipiford

    Tipiford Member

    Joined:
    Feb 5, 2014
    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Website Owner
    I am getting occasional emails from the cron job (not each time it runs as I would expect) and the error "find: /home/mail/DOMAIN.com/donotreply/cur: No such file or directory" is confusing as I am copying and pasting from the address line of the file manager. Permissions for the folders are 751. What might I be doing wrong?
     
  10. Tipiford

    Tipiford Member

    Joined:
    Feb 5, 2014
    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Website Owner
    Thanx, Vanessa for the more explicit direction. I tried your code with an updated and accurate path:

    /home/mail/domain.com/donotreply/cur -name "\*.\*" -mtime +5 -exec rm {} \;

    I've also tried:

    /mail/domain.com/donotreply/cur -name "\*.\*" -mtime +5 -exec rm {} \;

    thinking maybe cpanel was starting from the home folder, but that didn't work either. And, permissions look okay.

    - - - Updated - - -

    oops. need to pay more attention with domain names, I guess.
     
    #10 Tipiford, Feb 8, 2014
    Last edited: Feb 9, 2014
  11. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,854
    Likes Received:
    676
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
  12. Tipiford

    Tipiford Member

    Joined:
    Feb 5, 2014
    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Website Owner
    Thanks for the advice and guidance, but I still cannot get this simple routine to work. One thing I have found under the File Manager's address bar was my "/home/" was actually named "/home2/" but neither does that work. (I had originally gotten the address from an FTP client which did not show the name of "home.") Correcting that, the code, as I understand it, is:

    find /home2/USERNAME/mail/.donotreply@DOMAIN_com/cur -name "\*.\*" -mtime +5 -exec rm {} \;

    and is not removing any files. Is there anything else I might look at, or am I destined to delete these files manually--this is a rarely looked at folder; it was set-up as a safe guard for companies I suspected of sending spam or giving out our address?
     
  13. vanessa

    vanessa Well-Known Member
    PartnerNOC

    Joined:
    Sep 26, 2006
    Messages:
    817
    Likes Received:
    22
    Trophy Points:
    18
    Location:
    Virginia Beach, VA
    cPanel Access Level:
    DataCenter Provider
    Any cron output?
     
  14. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,854
    Likes Received:
    676
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Hello :)

    Rather than manually deleting the files through a cron job, why not just setup a filter that discards any incoming email to that address? You could set this up using the User Level Filtering option in cPanel.

    Thank you.
     
  15. Tipiford

    Tipiford Member

    Joined:
    Feb 5, 2014
    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Website Owner
    I am getting occasional emails after some cron jobs, but most are ignored. Where would I look to see any output?

    - - - Updated - - -

    Or I could delete the email address. Neither is an option, I need to go in there from time to time to get a link or auth. code. I would like mails deleted after a given period--of like, 5 days.
     
  16. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,854
    Likes Received:
    676
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    I believe you are looking for a command more like this:

    Code:
    find /home/cphwtest04/mail/domain.com/cptest1/cur -type f -mtime +5 -exec rm {} \;
    Ensure you are careful when using any command with "rm" as any slight typing mistake could result in the deletion of additional files.

    Thank you.
     
  17. magicalwonders

    magicalwonders Well-Known Member

    Joined:
    Nov 21, 2012
    Messages:
    96
    Likes Received:
    0
    Trophy Points:
    6
    cPanel Access Level:
    Root Administrator
    I'm trying to get the same thing working in cPanel to empty a mailbox on one of my domains for any mail older than 2 or 3 days.

    Not sure I really understand the above command, but it looks like for a mailbox called myles@mydomain.com the command would be almost as follows -

    I'm not sure what the folder or name "cptest1" in the original example would translate to for things to work for me though? Is it the name to the left of the @mydomain.com? Which would give me the following -

    Myles
     
  18. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,854
    Likes Received:
    676
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Yes, "cptest1" is an example name of an email account. The second example you provided would delete all email in the "cur" directory for that email account that's older than two days.

    Thank you.
     
  19. magicalwonders

    magicalwonders Well-Known Member

    Joined:
    Nov 21, 2012
    Messages:
    96
    Likes Received:
    0
    Trophy Points:
    6
    cPanel Access Level:
    Root Administrator
    Thanks Michael. I appreciate the help. :)

    Myles
     
  20. rezman

    rezman Well-Known Member

    Joined:
    Feb 3, 2011
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    USA
    cPanel Access Level:
    Root Administrator
    I have the following bash script that runs from the cron every 24 hours.

    Code:
    #!/bin/bash
    
    find -P /home/<user>/mail/domian.com/*/.Trash/cur /home/<user>/mail/domian.com/*/.Trash/new -type f -mtime '+30'
    find -P /home/<user>/mail/domian.com/*/.spam/cur /home/<user>/mail/domian.com/*/.spam/new -type f -mtime '+30'
    find -P /home/<user>/mail/domian.com/*/new -type f -mtime '+90'
    Works wonders at deleting mail in the Trash and Spam folders that's over 30 days old. It takes maybe 20-30 seconds to process over 2700 mailboxes that use about 150 gigs of space.

    The 3rd line deletes mail from the inbox of accounts that people haven't logged into in over 90 days. We had to implement this policy a while back because people either started forwarding their mail or just stopped using the email account. I find this to be better than dealing with "Mailbox Quota Exceeded" bounces.
     
Loading...

Share This Page