Skip to main content

Having issues getting cron job to work

Comments

44 comments

  • vanessa
    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.
    0
  • cPanelMichael
    [quote="Tipiford, post: 1566332">Have tried this with and without the period found in the site's email address, and with and without the password in curly brackets.)
    A password is not used in a path to a file/directory. You would enter the username of the account instead. Thank you.
    0
  • Tipiford
    Would the username be in curly brackets? Or just the username between slashes?
    0
  • cPanelMichael
    You would enter the username the same way you enter the rest of the path. EX: /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.
    0
  • Tipiford
    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
    0
  • vanessa
    Try this one: 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.
    0
  • Tipiford
    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.
    0
  • Tipiford
    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?
    0
  • Tipiford
    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. [COLOR="silver">- - - Updated - - - oops. need to pay more attention with domain names, I guess.
    0
  • cPanelMichael
    The full path should be: /home/username/mail/domain.com/donotreply/cur/ You have to include your username in the path. Thank you.
    0
  • Tipiford
    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?
    0
  • vanessa
    Any cron output?
    0
  • cPanelMichael
    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.
    0
  • Tipiford
    I am getting occasional emails after some cron jobs, but most are ignored. Where would I look to see any output? [COLOR="silver">- - - 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.
    0
  • cPanelMichael
    I believe you are looking for a command more like this: 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.
    0
  • magicalwonders
    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 - [QUOTE]find /home/magicalw/mail/mydomain.com/cptest1/cur -type f -mtime +2 -exec rm {} \;
    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 - [QUOTE]find /home/magicalw/mail/mydomain.com/myles/cur -type f -mtime +2 -exec rm {} \;
    Myles
    0
  • cPanelMichael
    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.
    0
  • magicalwonders
    Thanks Michael. I appreciate the help. :) Myles
    0
  • rezman
    I have the following bash script that runs from the cron every 24 hours. #!/bin/bash find -P /home//mail/domian.com/*/.Trash/cur /home//mail/domian.com/*/.Trash/new -type f -mtime '+30' find -P /home//mail/domian.com/*/.spam/cur /home//mail/domian.com/*/.spam/new -type f -mtime '+30' find -P /home//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.
    0
  • Tipiford
    I am still wrestling with this issue. It seems like the staff here at cpanel could offer more solutions or at least some suggestions as to what to try next. As it now stands, here is the code that is not working: find /home2/mail/domain.com/donotreply/cur -type f "\*.\*" -mtime +2 -exec rm {} \; And here is the cron email I am getting: find: paths must precede expression Usage: find [path...] [expression] To me, it appears that this is a path issue, could it be that "home2" is a subset of "home" and is blocking any code in the crontab? Thanx, T
    0
  • cPanelMichael
    [quote="Tipiford, post: 1578691">It seems like the staff here at cpanel could offer more solutions or at least some suggestions as to what to try next. As it now stands, here is the code that is not working:
    It's generally against company guidelines to offer guidance on custom bash scripts, particularly concerning commands that involve removing files. That being said, if you look at the first post from page two of this thread, I offered an updated command, tested it, and confirmed it should work well if you replace the values with your own account information. The script from your last response does not reflect that script. Thank you.
    0
  • Tipiford
    I am fully aware of any disclaimer regarding company policy. I have forever been responsible for my own actions, and have never looked to the government, any company or any other person to be accountable for my actions. The difference in scripts is attributed to 1.) originally copying the path from my FTP client which did not show the "home2" part of the path, and 2.) I added "\*.\*" to the mix based on forum member Vanessa's suggestion. But neither, find /home2/mail/domain.com/donotreply/cur -type f -mtime +5 -exec rm {} \; nor find /home2/mail/domain.com/donotreply/cur -type f "\*.\*" -mtime +5 -exec rm {} \; is working, and therefore am suspecting a path issue. Could the "home2" be a pseudo address blocking me from the "true" address? Thanx T
    0
  • vanessa
    [quote="Tipiford, post: 1578821"> find /home2/mail/domain.com/donotreply/cur -type f -mtime +5 -exec rm {} \;
    What I see wrong with this is your path. You don't have a username after /home2: find /home2/USER/mail/domain.com/donotreply/cur -type f -mtime +5 -exec rm {} \;
    I tested this exactly on one of my servers and it works fine. Stop being so whiney.
    0
  • magicalwonders
    [quote="Tipiford, post: 1578821">I am fully aware of any disclaimer regarding company policy. I have forever been responsible for my own actions, and have never looked to the government, any company or any other person to be accountable for my actions.
    But you have been looking for help. :) Forum members have tried to assist you as best they can, (and solved your problem) yet you have come across as a bit ungrateful. That may not have been your intention, but that is how it looks.
    0
  • hhazeley
    [quote="cPanelMichael, post: 1570381">I believe you are looking for a command more like this: 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.
    I used the code format above email got deleted but it still showing i have 99% usage but there are no mails. Did i miss a switch or something? Thanks
    0
  • vanessa
    [quote="hhazeley, post: 1590731">I used the code format above email got deleted but it still showing i have 99% usage but there are no mails. Did i miss a switch or something? Thanks
    Wait for your mail quota to update (happens every night during cpanel updates), or delete the quota file from the email account and let it regenerate.
    0
  • hhazeley
    Thanks. That worked
    0
  • cPanelMichael
    [quote="hhazeley, post: 1590752">Thanks. That worked
    Thank you for updating us with the outcome. I am happy to see the issue you encountered is now resolved.
    0
  • magicalwonders
    I seem to be having an issue getting this working. I have set up two cron jobs to empty two mailboxes. Here's the cron for one of them - [QUOTE]find /home/magicalw/mail/domain.com/myles/cur -type f -mtime +1 -exec rm {} \;
    This is set to run once a day. 0 0 * * * The first time I add the cron it seems to work just once and the mailbox is emptied. However, no cron output is received. After that the mailboxes continue to accumulate mail. If I edit the cron to change the frequency of when it runs, it will action successfully again just once and empty boxes, and then fail again when it is next due to run. Not sure what is happening. I'd be grateful If anyone can advise on what I can try next? Many thanks, Myles
    0
  • cPanelMichael
    [QUOTE]The first time I add the cron it seems to work just once and the mailbox is emptied. However, no cron output is received. After that the mailboxes continue to accumulate mail.
    Have you verified the "crond" service is running? Try restarting it via: service crond restart
    Also, did you verify emails exist in the directory right after the cron job runs? Thank you.
    0

Please sign in to leave a comment.