Amateur needs help with simple Cron job

Dortro

Member
Aug 2, 2021
16
2
3
Nederland
cPanel Access Level
Website Owner
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: [email protected]

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
 
Last edited by a moderator:

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
6,810
895
313
cPanel Access Level
Root Administrator
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:

Code:
find /home/username/mail/domain.com/emailuser/cur/ -type f -mtime +7 | xargs rm -rf
 

Dortro

Member
Aug 2, 2021
16
2
3
Nederland
cPanel Access Level
Website Owner
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/domain.com/emailuser/cur/ -type f -mtime +7 | xargs rm -rf

With user name the cpa el current user identifyer, domain.com my domain, emailuser test ( in my case)? What is cur?

Maybe another stupid question: Inbox is nowhere mentioned, is that ok?

Thanks,
Robert
 

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
6,810
895
313
cPanel Access Level
Root Administrator
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
 

Dortro

Member
Aug 2, 2021
16
2
3
Nederland
cPanel Access Level
Website Owner
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 [email protected])

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 [email protected]’s inox)

sorry!

Robert
 

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
6,810
895
313
cPanel Access Level
Root Administrator
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:

Code:
 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.
 

Dortro

Member
Aug 2, 2021
16
2
3
Nederland
cPanel Access Level
Website Owner
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!
 

Dortro

Member
Aug 2, 2021
16
2
3
Nederland
cPanel Access Level
Website Owner
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!!
 

Dortro

Member
Aug 2, 2021
16
2
3
Nederland
cPanel Access Level
Website Owner
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