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!

Move files from one directory to another with cron job

Discussion in 'General Discussion' started by greektranslator, Dec 28, 2014.

  1. greektranslator

    greektranslator Active Member

    Joined:
    Jun 5, 2011
    Messages:
    28
    Likes Received:
    0
    Trophy Points:
    51
    Location:
    Greece
    cPanel Access Level:
    Root Administrator
    I tried to run this script:

    Code:
    #!/bin/bash
    
    $sDirectory="/home/mysite/public_html/folder/test"
    $snew="/home/mysite/public_html/folder/test1"
    
    find $sDirectory -type f -maxdepth 1 -name "*.htm*" -exec mv {} $snew \;
    But it returns:
    No such file or directory for both directories (I can confirm the directories exist)

    I have placed the script in /home directory
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. 24x7server

    24x7server Well-Known Member

    Joined:
    Apr 17, 2013
    Messages:
    1,834
    Likes Received:
    85
    Trophy Points:
    78
    Location:
    India
    cPanel Access Level:
    Root Administrator
    What is the output of following command ?

    Code:
    ls -ld /home/mysite/public_html/folder/test
    ls -ld /home/mysite/public_html/folder/test1
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. greektranslator

    greektranslator Active Member

    Joined:
    Jun 5, 2011
    Messages:
    28
    Likes Received:
    0
    Trophy Points:
    51
    Location:
    Greece
    cPanel Access Level:
    Root Administrator
    Here it is:

    2014-12-30_142303.png
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. cPanelPeter

    cPanelPeter Technical Analyst III
    Staff Member

    Joined:
    Sep 23, 2013
    Messages:
    575
    Likes Received:
    20
    Trophy Points:
    93
    cPanel Access Level:
    Root Administrator
    Twitter:
    Hello,

    Remove the $ from the first 2 lines...

    It should be:

    Code:
    sDirectory="/home/mysite/public_html/folder/test"
    snew="/home/mysite/public_html/folder/test1"
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. greektranslator

    greektranslator Active Member

    Joined:
    Jun 5, 2011
    Messages:
    28
    Likes Received:
    0
    Trophy Points:
    51
    Location:
    Greece
    cPanel Access Level:
    Root Administrator
    Thanks! It worked.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. Nilkesh Patel

    Nilkesh Patel Registered

    Joined:
    Oct 9, 2014
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Ahmedabad, India, India
    cPanel Access Level:
    Website Owner
    Thanks... I had also the same problem.
     
  7. greektranslator

    greektranslator Active Member

    Joined:
    Jun 5, 2011
    Messages:
    28
    Likes Received:
    0
    Trophy Points:
    51
    Location:
    Greece
    cPanel Access Level:
    Root Administrator
    How is it possible to adapt the following bit

    -name "*.htm*"

    So that it moves all files APART from .htaccess?
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  8. madmanmachines

    madmanmachines Well-Known Member

    Joined:
    Nov 28, 2014
    Messages:
    94
    Likes Received:
    4
    Trophy Points:
    8
    cPanel Access Level:
    Root Administrator
    Hi greektranslator,

    '! -name .htaccess' would be necessary as in

    Code:
    find $sDirectory -type f -maxdepth 1 -name "*.htm*" ! -name .htaccess -exec mv {} $snew \;
    Thanks,
     
  9. greektranslator

    greektranslator Active Member

    Joined:
    Jun 5, 2011
    Messages:
    28
    Likes Received:
    0
    Trophy Points:
    51
    Location:
    Greece
    cPanel Access Level:
    Root Administrator
    Thanks, how can I add more extensions to the excluded list?
    I have this but after a test run I found in destination directory some strange files like .autorespond-loopprotect, .bash_history, .spamassassinenable, .cpanel-ducache, .bash_profile which appear to have been in the root of the specific account?

    #!/bin/bash

    sDir1="/home/account/folder1"
    sDir2="/home/account/folder"
    snew="/home/1"

    find $sDir1 -type f -mmin +30 -maxdepth 1 -not -name "*.htac*" -exec mv {} $snew \;
    find $sDir2 -type f -mmin +30 -maxdepth 1 -not -name "*.htac*" -exec mv {} $snew \;
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
    #9 greektranslator, Jan 19, 2015
    Last edited: Jan 19, 2015
  10. madmanmachines

    madmanmachines Well-Known Member

    Joined:
    Nov 28, 2014
    Messages:
    94
    Likes Received:
    4
    Trophy Points:
    8
    cPanel Access Level:
    Root Administrator
    Hi,

    This can easily be found by googling... linux find multiple names

    Code:
    find $sDirectory -type f -maxdepth 1 -name "*.htm*" ! \( -name  .htaccess -o -name "other-string-here" \) -exec mv {} $snew \;
    It looks like you have moved essential cPanel files out of their necessary locations. Hopefully you made a backup prior to these changes or you are able to put these back properly.

    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