How to clean /tmp directory automatically in Linux/cPanel using tmpwatch

The “tmpwatch ” command in linux is to removes files which haven’t been accessed for a period of time. The 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.

If you are noticing “/tmp” getting overloaded with files and not sure which files/folders to delete – you better use “tmpwatch” to cleanup or delete files/folders from the “/tmp” directory.

You’ll need SSH root access to install tmpwatch and add it in the cron. If your server is inaccessible due to “/tmp” getting full – you may restart the server and that should free up some space after reboot.

  1. Login to the server as root using SSH
  2. Run the following command:

    #yum install tmpwatch -y

  3. To delete temporary files (for example after every 12 hours) run the following command:

    #/usr/sbin/tmpwatch -am 12 /tmp

  4. The next step is to configure tmpwatch to run automatically through a cron. To do that type the following command:

    #crontab -e

  5. The above command will open the cron job list for the user root. Now go to the bottom and add the following line and save the file:

    0 4 * * * /usr/sbin/tmpwatch -am 12 /tmp

    If you are unable to add the above line, you may navigate to “/var/spool/cron” and open the cron file “root” with a text editor (such as, vi, nano). Add the line at the bottom and save the file:

    0 4 * * * /usr/sbin/tmpwatch -am 12 /tmp

Check the usage of “/tmp” and it should be clean by now.

Thank you.

Quota Problem in WHM: Enabling second level quota on an OpenVZ node

I am talking about a very common problem in cPanel/WHM based server or VPS. Fresh WHM based server often do not show proper quota allocation for the hosting accounts. It show ZERO usage and Unlimited quota. Fixing the problem in a dedicated server is quite straight forward. The “Initial Quota Setup” in WHM or the command ” /script/fixquota” will solve the problem. But VPSs requires a second level quota setup as the first level quota is configured during VPS container setup.

Solution is to enable second level quota on the node. To do it execute these commands on the node:

vzctl stop CTID
vzctl set CTID –quotaugidlimit 100 –save
vzctl start CTID

Then, if you’re under WHM, do the “Initial quota setup” thing or run “/script/fixquota” through SSH.

NOTE:

CTID is the container/vps id number.

On the second command,  –quotaugidlimit 100 <- this is the number that defines the max file owners. Example: you have 100 users into the vps, set it to 120. You have 300 users into the vps, set it to something more than 300. I’ve used 100 on this example because it’s a common average value. Keep in mind that the more you set, the more kernel memory overhead will be created.