Find the answer to your Linux question:
Results 1 to 8 of 8
hi guys i am new to coding and hope this will be easy. I am told I need to a cron job to auto delete files stored in a folder ...
  1. #1
    Just Joined!
    Join Date
    Jan 2009
    Posts
    3

    help with cron job>

    hi guys i am new to coding and hope this will be easy.
    I am told I need to a cron job to auto delete files stored in a folder on my ftp.
    I want the chosen folder to delete every file in the folder they are only .exe files but I need them deleted every 10 mins.

    can someone show me the code I need to get this working and how to do it.
    which files do i upload to the server ect...

    thanks againm save my life

  2. #2
    Linux Enthusiast Bemk's Avatar
    Join Date
    Sep 2008
    Location
    Oosterhout-NB, Netherlands
    Posts
    522
    If you do crontab -e you can edit your crontab.

    Here you can add/remove your cron jobs.

    In the comment at the top you can see a template of how things are ought to look(it does at least in Ubuntu).

    I have cron job that looks like this:

    Code:
    00 23 * * * /sbin/shutdown -h 0
    This will shut the system down every time you get at 11 PM.

    I think this should work for you:
    Code:
    00 * * * * /bin/rm [path files to be removed]
    10 * * * * /bin/rm [path files to be removed]
    20 * * * * /bin/rm [path files to be removed]
    30 * * * * /bin/rm [path files to be removed]
    40 * * * * /bin/rm [path files to be removed]
    50 * * * * /bin/rm [path files to be removed]
    This should run every 10 minutes, so I think you'll be okay (I'm not an expert using cron by the way, I only have that one job running).

  3. #3
    Linux Guru
    Join Date
    Oct 2007
    Location
    Tucson AZ
    Posts
    1,939
    The entry below should run your cron job every ten minutes.

    */10 * * * * /path/to/command

  4. #4
    Linux Enthusiast Bemk's Avatar
    Join Date
    Sep 2008
    Location
    Oosterhout-NB, Netherlands
    Posts
    522
    I think that'll work better. Just because of the fact that it's easier.

  5. #5
    Just Joined!
    Join Date
    Jan 2009
    Posts
    3
    ok so guys how would I insert this code?


    the cron is on my server as cpanel and it asks for standard or advanced.
    the folder i want to delete the files inside is public_html/updateserver
    its so my folder wont get bogged down with to many uploads.

    so whats the total code i need to copy and paste?
    I have this but it just never works?

    find /public_html/updateserver/ -mmin +10 -type f -exec rm {} \;

  6. #6
    Linux Guru
    Join Date
    Oct 2007
    Location
    Tucson AZ
    Posts
    1,939
    */10 * * * * rm -f /public_html/updateserver/*.exe
    The above should work to remove all .exe files in that directory. Haven't tried it so I would suggest you put an .exe file or two in a directory, run the command from command line to test.

  7. #7
    Just Joined!
    Join Date
    Jan 2009
    Posts
    3
    I just wanted to say I have searched the entire internet and not one person could help it was always poor code offered or offtopic chat, but this place is greatm you got the code spot on!

    so if anyone else have my issue this code works fine!

    great job!

  8. #8
    Linux Guru
    Join Date
    Oct 2007
    Location
    Tucson AZ
    Posts
    1,939
    Glad it worked. Didn't have a chance to test it which is why I suggested you try on dummy files. Have fun!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...