Community Forums
Connect with us on LinkedIn
+ Reply to Thread
Results 1 to 6 of 6
  1. #1
    Member
    Join Date
    Jun 2003
    Location
    the dark side of the moon
    Posts
    31

    Question how to make a cron job

    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:
    =====================
    Rebelo

  2. #2
    Member
    Join Date
    Jun 2003
    Posts
    396

    Default cront to remov 30 day old files

    you couild use:
    find . -type f -mtime 30 -exec rm {} \;
    Do some home work. The find . tells it to start from right here so you would actually want something like
    find /home/username
    the -type f tells it a filetype

    the -mtime tells it 30 days old.

    So
    find /home/username/ -type -f -mtime 30 -exec rm {}\;
    would remove ALL files over 30 days old.

    This should give you a great start.

    cPanel.net Support Ticket Number:
    -Albert

  3. #3
    Member
    Join Date
    Jun 2003
    Location
    the dark side of the moon
    Posts
    31

    Default

    Getting the following error by email:

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

    Any ideas ?

    cPanel.net Support Ticket Number:
    =====================
    Rebelo

  4. #4
    Member
    Join Date
    Jun 2003
    Posts
    396

    Default

    I had a typo,

    you do not use -f

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

    cPanel.net Support Ticket Number:
    -Albert

  5. #5
    Member
    Join Date
    Jun 2003
    Location
    the dark side of the moon
    Posts
    31

    Default

    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:
    =====================
    Rebelo

  6. #6
    Member
    Join Date
    Mar 2003
    Location
    Dallas, TX
    Posts
    45

    Default

    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:

Similar Threads & Tags
Similar threads

  1. Cron Job
    By kiwis in forum New User Questions
    Replies: 1
    Last Post: 12-17-2008, 05:19 AM
  2. Replies: 3
    Last Post: 12-09-2006, 02:44 PM
  3. Cron job
    By john_24 in forum New User Questions
    Replies: 1
    Last Post: 08-07-2006, 05:43 AM
  4. Cron Job
    By HyperVirus in forum cPanel and WHM Discussions
    Replies: 4
    Last Post: 01-01-2005, 03:06 PM
  5. HELP! How to make a cron job in Cpanel?
    By EarthIndex in forum cPanel and WHM Discussions
    Replies: 3
    Last Post: 10-07-2004, 11:30 AM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube