Cron job to move directory with yesterday's date to another directory

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP








up vote
0
down vote

favorite












  1. I have an image upload system on my website in home1 directory which has folders in this form 2018/04/19/abc.jpg (year/mm/dd/finename). I need to set up a cron job to copy/move folder contents of the folder from 3 days back, i.e. 16 if running on 19, 17 if running on 20, and so on, to a corresponding folder in home2.



  2. Once the directory contents have been moved, I need to place an htaccess in the folder redirecting to the new directory, like this:



    RewriteEngine On
    RewriteCond %HTTP_HOST ^example.com$ [OR]
    RewriteCond %HTTP_HOST ^www.example.com$
    RewriteRule ^(.*)$ https://example.com/new_directory/uploads/YYYY/MM/DD/$1 [R=301,L]


    Basically the year, month and date should be dynamically generated in the htaccess file, corresponding to the directory that was copied



Please assist with the cron job.







share|improve this question


























    up vote
    0
    down vote

    favorite












    1. I have an image upload system on my website in home1 directory which has folders in this form 2018/04/19/abc.jpg (year/mm/dd/finename). I need to set up a cron job to copy/move folder contents of the folder from 3 days back, i.e. 16 if running on 19, 17 if running on 20, and so on, to a corresponding folder in home2.



    2. Once the directory contents have been moved, I need to place an htaccess in the folder redirecting to the new directory, like this:



      RewriteEngine On
      RewriteCond %HTTP_HOST ^example.com$ [OR]
      RewriteCond %HTTP_HOST ^www.example.com$
      RewriteRule ^(.*)$ https://example.com/new_directory/uploads/YYYY/MM/DD/$1 [R=301,L]


      Basically the year, month and date should be dynamically generated in the htaccess file, corresponding to the directory that was copied



    Please assist with the cron job.







    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      1. I have an image upload system on my website in home1 directory which has folders in this form 2018/04/19/abc.jpg (year/mm/dd/finename). I need to set up a cron job to copy/move folder contents of the folder from 3 days back, i.e. 16 if running on 19, 17 if running on 20, and so on, to a corresponding folder in home2.



      2. Once the directory contents have been moved, I need to place an htaccess in the folder redirecting to the new directory, like this:



        RewriteEngine On
        RewriteCond %HTTP_HOST ^example.com$ [OR]
        RewriteCond %HTTP_HOST ^www.example.com$
        RewriteRule ^(.*)$ https://example.com/new_directory/uploads/YYYY/MM/DD/$1 [R=301,L]


        Basically the year, month and date should be dynamically generated in the htaccess file, corresponding to the directory that was copied



      Please assist with the cron job.







      share|improve this question














      1. I have an image upload system on my website in home1 directory which has folders in this form 2018/04/19/abc.jpg (year/mm/dd/finename). I need to set up a cron job to copy/move folder contents of the folder from 3 days back, i.e. 16 if running on 19, 17 if running on 20, and so on, to a corresponding folder in home2.



      2. Once the directory contents have been moved, I need to place an htaccess in the folder redirecting to the new directory, like this:



        RewriteEngine On
        RewriteCond %HTTP_HOST ^example.com$ [OR]
        RewriteCond %HTTP_HOST ^www.example.com$
        RewriteRule ^(.*)$ https://example.com/new_directory/uploads/YYYY/MM/DD/$1 [R=301,L]


        Basically the year, month and date should be dynamically generated in the htaccess file, corresponding to the directory that was copied



      Please assist with the cron job.









      share|improve this question













      share|improve this question




      share|improve this question








      edited Apr 19 at 19:19









      wjandrea

      7,16342255




      7,16342255










      asked Apr 19 at 19:07









      dc09

      31




      31




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          You'll need to test this and adjust paths. Feel free to edit this answer to suit your needs after you do. But, it's something like this:



          #!/bin/bash
          THREEDAYSAGO=$(date +%Y/%m/%d --date='3 days ago')
          SRC="~/home1/"
          DEST="~/home2/"

          mv -f $SRC/$THREEDAYSAGO $DEST/$THREEDAYSAGO
          cat << EOF >/$DEST/$THREEDAYSAGO/.htaccess
          RewriteEngine On
          RewriteCond %HTTP_HOST ^example.com$ [OR]
          RewriteCond %HTTP_HOST ^www.example.com$
          RewriteRule ^(.*)$ https://example.com/new_directory/uploads/$THREEDAYSAGO/$1 [R=301,L]
          EOF


          Then in your crontab (crontab -e):



          # Every day at 12:00am
          0 0 * * * /path/to/my/script





          share|improve this answer




















            Your Answer







            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "89"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1026496%2fcron-job-to-move-directory-with-yesterdays-date-to-another-directory%23new-answer', 'question_page');

            );

            Post as a guest






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            1
            down vote



            accepted










            You'll need to test this and adjust paths. Feel free to edit this answer to suit your needs after you do. But, it's something like this:



            #!/bin/bash
            THREEDAYSAGO=$(date +%Y/%m/%d --date='3 days ago')
            SRC="~/home1/"
            DEST="~/home2/"

            mv -f $SRC/$THREEDAYSAGO $DEST/$THREEDAYSAGO
            cat << EOF >/$DEST/$THREEDAYSAGO/.htaccess
            RewriteEngine On
            RewriteCond %HTTP_HOST ^example.com$ [OR]
            RewriteCond %HTTP_HOST ^www.example.com$
            RewriteRule ^(.*)$ https://example.com/new_directory/uploads/$THREEDAYSAGO/$1 [R=301,L]
            EOF


            Then in your crontab (crontab -e):



            # Every day at 12:00am
            0 0 * * * /path/to/my/script





            share|improve this answer
























              up vote
              1
              down vote



              accepted










              You'll need to test this and adjust paths. Feel free to edit this answer to suit your needs after you do. But, it's something like this:



              #!/bin/bash
              THREEDAYSAGO=$(date +%Y/%m/%d --date='3 days ago')
              SRC="~/home1/"
              DEST="~/home2/"

              mv -f $SRC/$THREEDAYSAGO $DEST/$THREEDAYSAGO
              cat << EOF >/$DEST/$THREEDAYSAGO/.htaccess
              RewriteEngine On
              RewriteCond %HTTP_HOST ^example.com$ [OR]
              RewriteCond %HTTP_HOST ^www.example.com$
              RewriteRule ^(.*)$ https://example.com/new_directory/uploads/$THREEDAYSAGO/$1 [R=301,L]
              EOF


              Then in your crontab (crontab -e):



              # Every day at 12:00am
              0 0 * * * /path/to/my/script





              share|improve this answer






















                up vote
                1
                down vote



                accepted







                up vote
                1
                down vote



                accepted






                You'll need to test this and adjust paths. Feel free to edit this answer to suit your needs after you do. But, it's something like this:



                #!/bin/bash
                THREEDAYSAGO=$(date +%Y/%m/%d --date='3 days ago')
                SRC="~/home1/"
                DEST="~/home2/"

                mv -f $SRC/$THREEDAYSAGO $DEST/$THREEDAYSAGO
                cat << EOF >/$DEST/$THREEDAYSAGO/.htaccess
                RewriteEngine On
                RewriteCond %HTTP_HOST ^example.com$ [OR]
                RewriteCond %HTTP_HOST ^www.example.com$
                RewriteRule ^(.*)$ https://example.com/new_directory/uploads/$THREEDAYSAGO/$1 [R=301,L]
                EOF


                Then in your crontab (crontab -e):



                # Every day at 12:00am
                0 0 * * * /path/to/my/script





                share|improve this answer












                You'll need to test this and adjust paths. Feel free to edit this answer to suit your needs after you do. But, it's something like this:



                #!/bin/bash
                THREEDAYSAGO=$(date +%Y/%m/%d --date='3 days ago')
                SRC="~/home1/"
                DEST="~/home2/"

                mv -f $SRC/$THREEDAYSAGO $DEST/$THREEDAYSAGO
                cat << EOF >/$DEST/$THREEDAYSAGO/.htaccess
                RewriteEngine On
                RewriteCond %HTTP_HOST ^example.com$ [OR]
                RewriteCond %HTTP_HOST ^www.example.com$
                RewriteRule ^(.*)$ https://example.com/new_directory/uploads/$THREEDAYSAGO/$1 [R=301,L]
                EOF


                Then in your crontab (crontab -e):



                # Every day at 12:00am
                0 0 * * * /path/to/my/script






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Apr 20 at 4:54









                dpb

                4,90911545




                4,90911545



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1026496%2fcron-job-to-move-directory-with-yesterdays-date-to-another-directory%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Popular posts from this blog

                    Which professions warranted travel in Medieval times?

                    How do so many people here on Academia.SE, and in general, afford lavish higher education programs?

                    Trouble downloading packages list due to a “Hash sum mismatch” error