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.

how to make a cron job

Discussion in 'General Discussion' started by rebelo, Sep 5, 2003.

  1. rebelo

    rebelo Active Member

    Joined:
    Jun 30, 2003
    Messages:
    31
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    the dark side of the moon
    Hi,
    Rookie question:
    Need to delete automaticaly the files in one special folder that are older than 30 days (th
    ese files are. txt extension and cretaed by a cgi script).
    Believe, by what I´ve read, that a cron job would do it.
    How to proceed ?
    Do we need a just a command in the c panel cronjob window ?
    What to write in that command ?

    Any help would be appreciated

    cPanel.net Support Ticket Number:
     
  2. asmithjr

    asmithjr Well-Known Member

    Joined:
    Jun 13, 2003
    Messages:
    475
    Likes Received:
    1
    Trophy Points:
    18
    cront to remov 30 day old files

    you couild use:
    Do some home work. The find . tells it to start from right here so you would actually want something like
    the -type f tells it a filetype

    the -mtime tells it 30 days old.

    So
    would remove ALL files over 30 days old.

    This should give you a great start.

    cPanel.net Support Ticket Number:
     
  3. rebelo

    rebelo Active Member

    Joined:
    Jun 30, 2003
    Messages:
    31
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    the dark side of the moon
    Getting the following error by email:

    find: invalid argument `-f' to `-type'

    Any ideas ?

    cPanel.net Support Ticket Number:
     
  4. asmithjr

    asmithjr Well-Known Member

    Joined:
    Jun 13, 2003
    Messages:
    475
    Likes Received:
    1
    Trophy Points:
    18
    I had a typo,

    you do not use -f

    find /home/usrname -type f -mtime 30 -exec rm {} \;

    cPanel.net Support Ticket Number:
     
  5. rebelo

    rebelo Active Member

    Joined:
    Jun 30, 2003
    Messages:
    31
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    the dark side of the moon
    Does not worK :-(
    Have changed for 2 days to test but cretaed file still ther after a week.

    find /home/myusername/public_html/mydirectory -type f -mtime 2 -exec rm {} \;

    what could be the problem ?

    cPanel.net Support Ticket Number:
     
  6. cortices

    cortices Well-Known Member

    Joined:
    Mar 10, 2003
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Dallas, TX
    man find is your friend.

    asmithjr pointed you in the right direction. There is just one thing wrong with the command he supplied.

    Use -mtime -30 instead of -mtime 30. When using just "30" it only finds files that were modified exactly 30 days ago. When using "-30" it finds all files modified any time within the last 30 days.

    Also, you might want to use -ctime instead of -mtime as mtime represents the last time the file was modified which may or may not be the same time it was actually created.

    cPanel.net Support Ticket Number:
     
Loading...

Share This Page