script to delete

Discussion in 'Programming/Scripts' started by Mahir, Nov 13, 2005.

  1. Mahir

    Mahir New Member

    Hello can anyone help me to make a script that everynight 02:00 linux automaticly empty 2 directory's?

    /var/www/web2/web/mahir/png
    /var/www/web2/web/mahir/tmp

    is that possible ?
     
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    Save this script as e.g. /usr/bin/emptydir.sh


    Code:
    #!/bin/bash
    
    rm -rf /var/www/web2/web/mahir/png
    rm -rf /var/www/web2/web/mahir/tmp
    Then make it executable:

    Code:
    chmod +x /usr/bin/emptydir.sh
    Then edit your crontab with the command:

    Code:
    crontab -e
    and add a line:

    Code:
    59 23 * * * /usr/bin/emptydir.sh &> /dev/null
     
  3. falko

    falko Super Moderator ISPConfig Developer

    To run the cron job at 02.00h, the line should be
    Code:
    0 2 * * * /usr/bin/emptydir.sh &> /dev/null
     
  4. till

    till Super Moderator Staff Member ISPConfig Developer

    You're right, seems I've not read the post completely :) Have not seen that a time was mentioned.
     
  5. Mahir

    Mahir New Member

    /usr/bin/ulyaothdelete.sh
    Code:
    #!/bin/bash
    
    rm -f /var/www/web2/web/gd-rppng/png/*.png
    rm -f /var/www/web2/web/gd-rppng/tmp/*.txt
    
    chmod +x /usr/bin/ulyaothdelete.sh
    crontab -e

    and i added
    0 2 * * * /usr/bin/ulyaothdelete.sh &> /dev/null

    So now this should be ok ?
     
    Last edited: Nov 14, 2005
  6. till

    till Super Moderator Staff Member ISPConfig Developer

    It deletes the directories. If you only want to delte the contents inside of the directories, you can use this script:


    Code:
    #!/bin/bash
    
    rm -rf /var/www/web2/web/mahir/png/*
    rm -rf /var/www/web2/web/mahir/tmp/*
     
  7. Mahir

    Mahir New Member

    Thank u verymuch :) it works perfect :D
     

Share This Page