Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

deleting files on a cronjob

Discussion in 'General Discussion' started by alankru, Mar 22, 2006.

  1. alankru

    alankru Member

    Joined:
    Jan 2, 2006
    Messages:
    22
    Likes Received:
    0
    Trophy Points:
    151
    cPanel Access Level:
    Root Administrator
    Hi
    I would like a shell script which I can run via cron to:
    1. restore a mysql database
    2. delete a load of files
    3. copy a load of files from elsewhere
    I believe the best way todo this is to create a shell script and then call it from cron? I am a newbie though I'm afraid and creating shell scripts is something I don't know how todo. :eek:

    Effectively, this is what I want:

    1. Restore mysql database file "/home/akwsdemo/akwsdemo_forum.sql" to database "akwsdemo_forum" using mysql user "akwsdemo_forumer".

    2. Remove all files in the following folders (but not the folders themselves):
    /home/akwsdemo/public_html/mkportal/blog
    /home/akwsdemo/public_html/mkportal/blog/images
    /home/akwsdemo/public_html/mkportal/modules/downloads/file
    /home/akwsdemo/public_html/mkportal/modules/gallery/album
    /home/akwsdemo/public_html/mkportal/modules/reviews/images
    /home/akwsdemo/public_html/forum/uploads

    3. Copy the following files to the following directories:
    /home/akwsdemo/mkportal.bak/index.html -> to -> /home/akwsdemo/public_html/mkportal/blog
    /home/akwsdemo/mkportal.bak/tpl_blog.html -> to -> /home/akwsdemo/public_html/mkportal/blog
    /home/akwsdemo/mkportal.bak/index.html -> to -> /home/akwsdemo/public_html/mkportal/blog/images
    /home/akwsdemo/mkportal.bak/tmp -> to -> /home/akwsdemo/public_html/mkportal/modules/downloads/file
    /home/akwsdemo/mkportal.bak/a_no_image.gif -> to -> /home/akwsdemo/public_html/mkportal/modules/gallery/album
    /home/akwsdemo/mkportal.bak/a_no_image.gif -> to -> /home/akwsdemo/public_html/mkportal/modules/reviews/images
    /home/akwsdemo/mkportal.bak/index.html -> to -> /home/akwsdemo/public_html/forum/uploads

    ..and that's it. If anyone is able to help me with this I would appreciate it. Thanks!
     
  2. nothsa

    nothsa Well-Known Member

    Joined:
    Nov 30, 2004
    Messages:
    69
    Likes Received:
    0
    Trophy Points:
    156
    Obviously you should check this through before you use it. In the mysql line, replace "password" with the password for the account.

    Here we go:

    Code:
    #!/bin/bash
    mysql -uakwsdemo_forumer -ppassword akwsdemo_forum < /home/akwsdemo/akwsdemo_forum.sql
    rm -dfr /home/akwsdemo/public_html/mkportal/blog/*
    rm -dfr /home/akwsdemo/public_html/mkportal/blog/images/*
    rm -dfr /home/akwsdemo/public_html/mkportal/modules/downloads/file/*
    rm -dfr /home/akwsdemo/public_html/mkportal/modules/gallery/album/*
    rm -dfr /home/akwsdemo/public_html/mkportal/modules/reviews/images/*
    rm -dfr /home/akwsdemo/public_html/forum/uploads/*
    
    cp -a /home/akwsdemo/mkportal.bak/index.html /home/akwsdemo/public_html/mkportal/blog
    cp -a /home/akwsdemo/mkportal.bak/tpl_blog.html /home/akwsdemo/public_html/mkportal/blog
    cp -a /home/akwsdemo/mkportal.bak/index.html /home/akwsdemo/public_html/mkportal/blog/images
    cp -a /home/akwsdemo/mkportal.bak/tmp /home/akwsdemo/public_html/mkportal/modules/downloads/file
    cp -a /home/akwsdemo/mkportal.bak/a_no_image.gif /home/akwsdemo/public_html/mkportal/modules/gallery/album
    cp -a /home/akwsdemo/mkportal.bak/a_no_image.gif /home/akwsdemo/public_html/mkportal/modules/reviews/images
    cp -a /home/akwsdemo/mkportal.bak/index.html /home/akwsdemo/public_html/forum/uploads
    
     
  3. alankru

    alankru Member

    Joined:
    Jan 2, 2006
    Messages:
    22
    Likes Received:
    0
    Trophy Points:
    151
    cPanel Access Level:
    Root Administrator
    Thank you!:D
    I uploaded it into the directory /home/akwsdemo and gave it 755 permissions. I then went into cpanel and entered
    1 * * * * /home/akwsdemo/demo.sh
    Now, I don't get any email with an output though?
    So I tried in SSH:
    Code:
    [/home/akwsdemo]# source demo.sh
    
    Result:
    Code:
    : No such file or directoryemo_forum.sql
    : command not found
    ..and then it went onto the cp bit
    Is there something I have done wrong?
    Thanks.:)
     
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice