1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Cron job to empty directory each day?

Discussion in 'Site & Server Administration' started by Kerosene, Apr 4, 2007.

  1. #1
    I'm trying to setup a cron job in cPanel to empty a cache directory every day at 3am. Doesn't seem to be working - what am I doing wrong?

    [​IMG]
     
    Kerosene, Apr 4, 2007 IP
  2. eddy2099

    eddy2099 Peon

    Messages:
    8,028
    Likes Received:
    568
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Well, if you just run 'rm' it will prompt you if you want to delete file by file and since it is automated, it will most probably get stuck at that stage.

    You can do a brute force no prompt deletion using

    rm -rf /home/whatever/public_html/cache/*

    The -rf will skip the prompt and delete everything which can be deleted in that folder. So make sure it is correct or else you find yourself losing not just those undesirable files but everything else too.
     
    eddy2099, Apr 4, 2007 IP
    Kerosene likes this.
  3. postcd

    postcd Well-Known Member

    Messages:
    1,037
    Likes Received:
    9
    Best Answers:
    1
    Trophy Points:
    190
    #3
    Hi, thank you, this looks to be 100% good command, but when i added it to my Crontab module in cPanel (shared hosting), it does not delete files in that folder:

    [​IMG]

    Please can anyone help me? Please

    There is no root folder like /home/myusername/ in shared hosting FTP...
     
    postcd, Aug 14, 2010 IP
  4. MirVB

    MirVB Peon

    Messages:
    70
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    If you have shared hosting, then you probably don't have permissions to remove those files/folders.

    If you have root access to the server, then type the following command (not recommended):
    chown username:username /mail/new/*

    With shared hosting, you will only be able to delete files/folder within your home directory. (/home/username)

    Hope that helps.
     
    MirVB, Aug 14, 2010 IP
  5. postcd

    postcd Well-Known Member

    Messages:
    1,037
    Likes Received:
    9
    Best Answers:
    1
    Trophy Points:
    190
    #5
    Thank you, i have reseller hosting and this is an shared account. I have not SSH root access.

    This is my main reseller FTP account on the most up level:
    [​IMG]

    is it ok?
     
    postcd, Aug 14, 2010 IP
  6. MirVB

    MirVB Peon

    Messages:
    70
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    You must have root access to the server for the command you want to run.

    If you explain what you want to do in more detail, maybe we can help you further. (please post a new thread, not on this old one)
     
    MirVB, Aug 14, 2010 IP
  7. postcd

    postcd Well-Known Member

    Messages:
    1,037
    Likes Received:
    9
    Best Answers:
    1
    Trophy Points:
    190
    #7
    Thank you, it is there.
     
    postcd, Aug 14, 2010 IP
  8. sudesh_poojari

    sudesh_poojari Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Hi,

    normaly server people create alias of usual commands like rm, vi

    so to delete from real rm command

    use: 'rm' -rf /home/whatever/public_html/cache/*

    dont miss the single quotes of rm they are required to call original rm command not the alias

    i hope this helps
     
    sudesh_poojari, Aug 17, 2010 IP
  9. postcd

    postcd Well-Known Member

    Messages:
    1,037
    Likes Received:
    9
    Best Answers:
    1
    Trophy Points:
    190
    #9
    Error message:
    rm: cannot lstat `/home/XXX/mail/new/*': Permission denied
     
    postcd, Aug 17, 2010 IP
  10. sudesh_poojari

    sudesh_poojari Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    I believe cache would have had 777 permission you could delete it,

    but mail folder will never have such permission rather more strict that only owner Or root user could fire it.

    I dont think your crontab with your user rights has permission to delete files from that folder (rather even can't view it).

    The user who has right to modify that folder can add this cronjob in his crontab

    can you (with user rights) modify it, if yes then ask your hosting provider to help as of why your cronjob is showing permission issue.

    i hope my english is good enough for you to understand.
     
    sudesh_poojari, Aug 17, 2010 IP
  11. postcd

    postcd Well-Known Member

    Messages:
    1,037
    Likes Received:
    9
    Best Answers:
    1
    Trophy Points:
    190
    #11
    I can even delete that folder or change its permissions. Maybe you are right it canwork when i change permissions to 777, not sure, but my hosting provider told me i canot delete files directly usng cron, maybe the simply disbled rm command and such for shared hosting.

    But anyway i have found where was the problem, i had wrong command in my Cronjob so it flooded that folder by error and successful cronjob messges.
    http://forums.digitalpoint.com/showthread.php?t=1906220#post14774756
     
    postcd, Aug 18, 2010 IP
  12. mellow-h

    mellow-h Peon

    Messages:
    750
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #12
    If they change the rm, this would probably disable the deletion from your file manager as well. rm is a basic command, I do not suppose they would intentionally disable this for any user. Try this on your cronjobs and you should find the truth!
     
    mellow-h, Aug 19, 2010 IP
  13. Avener

    Avener Well-Known Member

    Messages:
    244
    Likes Received:
    20
    Best Answers:
    1
    Trophy Points:
    135
    #13
    I'm using:
    rm -f /folder/* (This is only the short version, I do use the full location)

    It won't work.
    When I try the command in puTTy it works perfectly.
     
    Avener, Jul 1, 2012 IP