How do I achieve this via cronjobs in cPanel?

I have a couple of users on my WHM/cPanel and their trash folders need to be monitored and emptied every midnight. At the moment they are growing fast and I don't want to have to monitor them myself:

216992 MB /home/userone/.trash/[contents]
11138 MB /home/usertwo/.trash/[contents]

I use cPanel and know where to go into the WHM to set such cronjobs. I know how to set the frequency and other settings but what I dont' know is how to frame the cron job query itself as I don't know the syntax.

I asked the cPanel team to help me but they pointed me to their knowledgebase which is practically useless as it has hardly any information: https://documentation.cpanel.net/display/ALD/Cron+Jobs#CronJobs-Addacronjob

I would like to know how to write the two separate cronjobs that I need, each programmed to emptying these two folders midnightly.

thanks in advance
badwolfffAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Zephyr ICTCloud ArchitectCommented:
What if you make  a simple script and run it with cron every night/day... Something like:

#/bin/sh
/usr/bin/rm -rf  /home/userone/.trash/*
/usr/bin/rm -rf  /home/usertwo/.trash/*

Open in new window

badwolfffAuthor Commented:
Thanks. That's a really nice idea. I could add all I need to do in that script as I go along and add more users too.

Do I create the script using "sudo nano"?
And where do I save it and how to phrase the cronjob query?
(I know how to make the cron job run every midnight but I don't know how to write the query)

thanks
Zephyr ICTCloud ArchitectCommented:
Depends on how you are logged in, you can create it with a regular user and change the permissions of the file as needed, don't forget to set the executable bit (chmod +x script.sh)

The script can be placed where you want in principle, just refer the complete path in the script so the cronjob can find it. You need to either declare PATH in your script or use the complete path, otherwise the cronjob/script will fail.

And where do I save it and how to phrase the cronjob query?

Do you mean how to configure it in cron to call the script?

Something like this would run the script every midnight, you can leave the username off if not needed:

00 00 * * * USERNAME /path/to/script.sh

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.