Cron job to move directory with yesterday's date to another directory
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgO9GURib1T8z7lCwjOGLQaGtrueEthgQ8LO42ZX8cOfTqDK4jvDDpKkLFwf2J49kYCMNW7d4ABih_XCb_2UXdq5fPJDkoyg7-8g_YfRUot-XnaXkNYycsNp7lA5_TW9td0FFpLQ2APzKcZ/s1600/1.jpg)
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYQ0N5W1qAOxLP7t7iOM6O6AzbZnkXUy16s7P_CWfOb5UbTQY_aDsc727chyphenhyphen5W4IppVNernMMQeaUFTB_rFzAd95_CDt-tnwN-nBx6JyUp2duGjPaL5-VgNO41AVsA_vu30EJcipdDG409/s400/Clash+Royale+CLAN+TAG%2523URR8PPP.png)
up vote
0
down vote
favorite
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.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.
command-line bash apache2 cron
add a comment |Â
up vote
0
down vote
favorite
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.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.
command-line bash apache2 cron
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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.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.
command-line bash apache2 cron
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.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.
command-line bash apache2 cron
edited Apr 19 at 19:19
![](https://i.stack.imgur.com/eVuAv.png?s=32&g=1)
![](https://i.stack.imgur.com/eVuAv.png?s=32&g=1)
wjandrea
7,16342255
7,16342255
asked Apr 19 at 19:07
![](https://lh3.googleusercontent.com/-XdUIqdMkCWA/AAAAAAAAAAI/AAAAAAAAAAA/4252rscbv5M/photo.jpg?sz=32)
![](https://lh3.googleusercontent.com/-XdUIqdMkCWA/AAAAAAAAAAI/AAAAAAAAAAA/4252rscbv5M/photo.jpg?sz=32)
dc09
31
31
add a comment |Â
add a comment |Â
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
add a comment |Â
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
add a comment |Â
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
add a comment |Â
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
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
answered Apr 20 at 4:54
dpb
4,90911545
4,90911545
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password