Skip to main content

Amateur needs help with simple Cron job

Comments

26 comments

  • cPRex Jurassic Moderator
    Hey there! I wouldn't expect this to work as a default cPanel server does not have the /usr/bin/archivemail tool installed. Was that tool installed on your server? If I were doing something like this I would create a Bash script inside a file that searches for emails based on the timestamp, and then ensure that tuns every night. The following script can be potentially dangerous, so please use this with caution: find /home/username/mail/domain.com/emailuser/cur/ -type f -mtime +7 | xargs rm -rf
    0
  • Dortro
    Thank you cPRex! I do not think that tool is installed (don"t even know what it is) so, can I just replace the script in my Cron Job, which runs daily, with yours: find /home/username/mail/
    0
  • cPRex Jurassic Moderator
    You wouldn't be able to place that directly in the cron. You would want to create a file on the server named email_cron.sh, place that line of code in it, save the file, make it executable, and then setup this cron job: /bin/bash /home/username/email_cron.sh
    0
  • Dortro
    Ok, I will figure out how to do that (create a file, make it executable") How about this /cur/? Thanks and best regards, Robert
    0
  • cPRex Jurassic Moderator
    I'm not sure what you mean in relation to the /cur/ portion - can you get me more details?
    0
  • Dortro
    Sure! In your script : find /home/username/mail/domain.com/emailuser/cur/ -type f -mtime +7 | xargs rm -rf There are a number of things I think I understand: username: the cpanel identifier for the account. In my case nxsckg42kptp/ domain.com: in my case domain.com emailuser: in my case test (the emai address is start@domain.com) following that you have: /cur/ I do not know what that is/what I have to put there! As I said, I am completely new To all this. I do not need to learn a lot, I just hope to get this one thing (deleting emails older than x days from start@domain.com"s inox) sorry! Robert
    0
  • cPRex Jurassic Moderator
    The /cur directory is the physical location of the emails on the server. That would be more or less equivalent to the user's inbox. If you wanted to check all directories under the email account you could just stop the path after the email user like this: find /home/username/mail/domain.com/emailuser/ -type f -mtime +7 | xargs rm -rf
    and that would erase everything from the email account older than 7 days.
    0
  • Dortro
    Top!!
    0
  • Dortro
    Dear CPrex Through cPanel File Mager v3, I created email_cron.sh; Through edit, I entered and saved find/home/nxsckg42kptp/mail/vandortmond.com/ test/ -type f mtime +7 The permission of the file is 0644 (??is this ok?) I entered the cron job /bin/bash/home/nxsckg42kptp/email_cron.sh That should do it? Thanks!
    0
  • Dortro
    My Cron Job ran for the first time, and indeed: amateur! This the message I got: /usr/local/cpanel/bin/jailshell: /bin/bash/home/nxsckg42kptp/email_cron.sh: Not a directory Can you pls help one more time? It must now be something small" Thanks!!
    0
  • cPRex Jurassic Moderator
    It looks like you're just missing a space in the cron job formatting after the "/bin/bash" portion. Can you try adding that space?
    0
  • Dortro
    Did that! Will see tomorrow! Thanks, Robert
    0
  • cPRex Jurassic Moderator
    You could also temporarily change the time to something else, like * * * * * to make it run every minute to confirm it works, so you don't have to wait 24 hours.
    0
  • Dortro
    Permissions for email_cron.sh : 0644. Ok?
    0
  • cPRex Jurassic Moderator
    You'll likely find it needs to be 755 in order to execute properly.
    0
  • Dortro
    Changed to every minute"
    0
  • Dortro
    This is the result now: find: paths must precede expression: mtime Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expressio
    0
  • cPRex Jurassic Moderator
    In your command it looks like you have an extra "test/" section there: find /home/nxsckg42kptp/mail/vandortmond.com/ test/ -type f mtime +7 so that would be confusing find's search location.
    0
  • Dortro
    The email account is test@vandortmond.com, where you line said /email user/, I have put /test/
    0
  • cPRex Jurassic Moderator
    Correct, but there shouldn't be a space there - it's all one file path.
    0
  • Dortro
    find /home/nxsckg42kptp/mail/vandortmond.com/test/-type f mtime +2 | xargs rm -rf Above is the exact line I have now... The result is now: find: `/home/nxsckg42kptp/mail/vandortmond.com/test/-type': No such file or directory find: `f': No such file or directory find: `mtime': No such file or directory find: `+2': No such file or directory If I enter the space after test/ again, I get the previous result...
    0
  • Dortro
    Does this make sense to you (what happened to Fortran IV?)?
    0
  • cPRex Jurassic Moderator
    These issues still just seem like typos with the command. Here is what I would expect to see: find /home/username/mail/domain.com/emailuser/cur/ -type f -mtime +7 | xargs rm -rf
    Those errors indicate you don't have a space after your directory, as the "-type" error indicates the lack of space, and then all following errors are invalid flags from the missing "-type" command.
    0
  • Dortro
    I do not get any email messages and the older emails disappear! Wauw, thanks!!!
    0
  • cPRex Jurassic Moderator
    Great - I'm glad we were able to get there! I'd recommend changing that back to one just once a day instead of every minute though, just so there aren't any odd conflicts.
    0
  • Dortro
    Will do!
    0

Please sign in to leave a comment.