Amateur needs help with simple Cron job
Hello, my name is Robert and I am new to this forum.
I need some help with a simple Cron job to empty the inbox of one if my email users, please
my domain name is: domain.com
The email user us: test@vandortmond.com
this is the cron job I found to run every day to remove emails older than 7 days from the inbox:
/usr/bin/archivemail--quiet--delete--days 7 /home/nxsckg42kptp/mail/domain.com/test/inbox
nxsckg42kptp is the current user id of my cpanel account
Is this correct? It does not seem to work"
Thanks
-
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 -
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 -
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 -
I'm not sure what you mean in relation to the /cur/ portion - can you get me more details? 0 -
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 -
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 -
Top!! 0 -
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 -
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 -
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 -
Did that! Will see tomorrow! Thanks, Robert 0 -
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 -
Permissions for email_cron.sh : 0644. Ok? 0 -
You'll likely find it needs to be 755 in order to execute properly. 0 -
Changed to every minute" 0 -
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 -
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 -
The email account is test@vandortmond.com, where you line said /email user/, I have put /test/ 0 -
Correct, but there shouldn't be a space there - it's all one file path. 0 -
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 -
Does this make sense to you (what happened to Fortran IV?)? 0 -
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 -
I do not get any email messages and the older emails disappear! Wauw, thanks!!! 0 -
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 -
Will do! 0
Please sign in to leave a comment.
Comments
26 comments