Cronjob or rake task for automate a download, unzip and move to a specified directory
I'm not sure if this should be achieved using cron job or rake task.
There is this large zipped file (250MB+) that is provided by third-party, that is updated weekly. I can't be downloading it to my local machine and uploading to the server weekly to replace the old data. Is there anyway I can write such workflow:
- Download a zipped file from this URL:
http://download.abc.com/data.zip
every Sunday 4am. - Unzip it to
data
. - Move the folder, its subfolders and contents to
public/data
and replace oldpublic/data
.
Many thanks.
This sounds like a bash script. Install it with crontab -e
.
#!/bin/bash
cd /tmp
mkdir data
cd data
wget http://download.abc.com/data.zip
unzip data.zip
rm -rf /public/data/*
mv data/* /public/data/
chown -R www-data:www-data /public/data/
Didn't test it, but it should do that, what you want.
Don't forget to adapt owner/group www-data:www-data
to your own needs.
精彩评论