The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Move files from one directory to another with cron job

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

  1. greektranslator

    Joined:
    Jun 5, 2011
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    1
    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
     
  2. 24x7server

    24x7server Well-Known Member

    Joined:
    Apr 17, 2013
    Messages:
    1,146
    Likes Received:
    34
    Trophy Points:
    48
    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
     
  3. greektranslator

    Joined:
    Jun 5, 2011
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Greece
    cPanel Access Level:
    Root Administrator
  4. cPanelPeter

    cPanelPeter Technical Analyst III
    Staff Member

    Joined:
    Sep 23, 2013
    Messages:
    569
    Likes Received:
    15
    Trophy Points:
    18
    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"
    
     
  5. greektranslator

    Joined:
    Jun 5, 2011
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Greece
    cPanel Access Level:
    Root Administrator
  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

    Joined:
    Jun 5, 2011
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    1
    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?
     
  8. madmanmachines

    madmanmachines Well-Known Member

    Joined:
    Nov 28, 2014
    Messages:
    94
    Likes Received:
    3
    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

    Joined:
    Jun 5, 2011
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    1
    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 \;
     
    #9 greektranslator, Jan 19, 2015
    Last edited: Jan 19, 2015
  10. madmanmachines

    madmanmachines Well-Known Member

    Joined:
    Nov 28, 2014
    Messages:
    94
    Likes Received:
    3
    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