We often get support tickets from users worried that WHM is reporting that the tmp directory is either full or getting near to full and don’t know how to prevent this from happening. If you have root access to your server you can use tmpwatch to regularly purge the tmp dir and prevent any future warnings from WHM.
What is tmpwatch ?
tmpwatch recursively removes files which haven’t been accessed for a given time. Normally, it’s used to clean up directories which are used for temporary holding space such as /tmp.
How to set up tmpwatch
SSH into the server as root and then run the following commend to install tmpwatch
yum install tmpwatch -y
Once thats done you can run set up a cron job to regularly run tmpwatch. You can either manually edit the system cron file found at /var/spool/cron/root or execute the following via SSH
crontab -e
paste the following at the very end of the file
0 6 * * * /usr/sbin/tmpwatch -am 12 /tmp
Now you need to save the file. On a PC you use Control+X and on a mac you would use Command+X. When asked to confirm the edit you need to type in Y and then hit enter. All thats left to do now is restart the cron service by executing the following shell command
service crond restart
What did we just do there ?
Lets just break down what the command we added to the bottom of the cron file actually does. 0 6 * * * tells the cron to run at zero minutes past 6am every day of every month of every year. /usr/sbin/tmpwatch -am 12 /tmp calls the tmpwatch script with the options -am 12 /tmp. This tells the script to delete all files in the /tmp directory whose modification time was more then 12 hours ago.
More info
visit https://linux.die.net/man/8/tmpwatch for more info on how to use tmpwatch and its options