The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

cron to clean tmp

Discussion in 'General Discussion' started by uacomm, Apr 15, 2011.

  1. uacomm

    uacomm Member

    Joined:
    Apr 15, 2011
    Messages:
    22
    Likes Received:
    0
    Trophy Points:
    1
    My /tmp directory get 100% full in every 3 to 4 days which cause most of services un-accessible until I clean up the /tmp manually.

    How can I set a cron to auto lean /tmp daily/
     
  2. LinuxTechie

    LinuxTechie Well-Known Member

    Joined:
    Jan 22, 2011
    Messages:
    502
    Likes Received:
    2
    Trophy Points:
    18
    cPanel Access Level:
    Root Administrator
    Hello,

    I thinks you need to use tmpwatch.

    Definition: tmpwatch: The tmpwatch utility recursively searches through specified directories and removes files which have not been accessed in a specified period of time. Tmpwatch is normally used to clean up directories which are used for temporarily holding files (for example, /tmp). Tmpwatch ignores symlinks, won't switch filesystems and only removes empty directories and regular files.

    Please use the URL for cron details : /http://prefetch.net/blog/index.php/2009/05/01/automating-temporary-file-cleanup-with-tmpwatch/
     
  3. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,623
    Likes Received:
    21
    Trophy Points:
    38
    Location:
    somewhere over the rainbow
    cPanel Access Level:
    Root Administrator
    Please ensure not to set the cron times or tmpwatch to clear /tmp in less then a 6 to 12 hour period. If you have it clearing files that are younger than 6-12 hours (I've seen some users set it at 5 minutes), you will break some components such as EasyApache from working when it compiles. This is because EasyApache will write some temporary files to /tmp and take longer than 5 minutes to run.
     
  4. LinuxTechie

    LinuxTechie Well-Known Member

    Joined:
    Jan 22, 2011
    Messages:
    502
    Likes Received:
    2
    Trophy Points:
    18
    cPanel Access Level:
    Root Administrator
    Hey Friends,

    Yes, Tristan is true!
     
  5. uacomm

    uacomm Member

    Joined:
    Apr 15, 2011
    Messages:
    22
    Likes Received:
    0
    Trophy Points:
    1
    I have readout the above url for tmwatch but cannot understand how to set out it to clean in every 12 hours. So can you please give me step by step instructions that how can I set tmpwatch to clear it in every 12 hours.
     
  6. kernow

    kernow Well-Known Member

    Joined:
    Jul 23, 2004
    Messages:
    865
    Likes Received:
    9
    Trophy Points:
    18
    cPanel Access Level:
    Root Administrator
    Here you go:
    Code:
    0 */4 * * * /usr/sbin/tmpwatch -am 12 /tmp
    Switches used:
    m - make the decision about deleting a file based on the file’s mtime
    a - remove all file types
     
    #6 kernow, Apr 17, 2011
    Last edited: Apr 17, 2011
  7. uacomm

    uacomm Member

    Joined:
    Apr 15, 2011
    Messages:
    22
    Likes Received:
    0
    Trophy Points:
    1
    I have set that cron but still /tmp get full some times. So how can I determine what actually is the problem? Why tmp is getting full?
     
  8. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,743
    Likes Received:
    662
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    You can browse to the /tmp directory via the command line, and use the following commands to determine which files are using the most disk space:

    Code:
    # cd /tmp
    # du -sh * .[a-zA-Z]*
    
    Thank you.
     
  9. uacomm

    uacomm Member

    Joined:
    Apr 15, 2011
    Messages:
    22
    Likes Received:
    0
    Trophy Points:
    1
    I run that command and I looked /tmp folder via winscp root login. There are lot of files like:

    4.0K sess_fbec1bb87c9d1df25813f2fa8a0565cf
    0 sess_fbee02d8231866477dd6089ac8239f06


    But I think above types files are not problematic. I also see lot below types files:

    37M #sql_3287_0.MYD
    4.0K #sql_3287_0.MYI
    21M #sql_3287_1.MYD
    4.0K #sql_3287_1.MYI

    I don't know what types of these #sql_3287_0.MYD? These sql files are filling the /tmp so how can I prevent these files to filling the /tmp
     
  10. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,623
    Likes Received:
    21
    Trophy Points:
    38
    Location:
    somewhere over the rainbow
    cPanel Access Level:
    Root Administrator
    Those files are for MySQL for temporary MyISAM tables. To prevent MySQL from using /tmp for those temporary tables, you can change the tmpdir location for MySQL in /etc/my.cnf file. In the [mysqld] section of /etc/my.cnf, put the following:

    Code:
    tmpdir=/mysqltmp
    At that point, then create that directory:

    Code:
    mkdir /mysqltmp
    chown -R mysql:mysql /mysqltmp
    Then restart MySQL:

    Code:
    /etc/init.d/mysql restart
    At that point, any future temporary tables should end up writing to /mysqltmp instead. You can check it did change to that location by running the following command to check it:

    Code:
    mysqladmin var | grep tmpdir
     
Loading...

Share This Page