As the title explains, I'd need to take a file and put it into a zip archive once a day; also, the zip file has to be moved in /var/www/html, where a .php scripts allow users to download it.
- the absolute path of the file is
- I put all scripts file I need to run using cronjobs in
- I programmed the following cronjob using
sudo crontab -e, instead of
crontab -ebecause /var/www/html needs administrative privileges
The results of my thoughts are the followings:
cp /home/myuser/myworkingdir/file.txt /home/myuser/file.txt && cd /home/myuser && zip my-zip-file-$(date "+%b_%d_%Y_%H.%M.%S").zip file.txt && rm file.txt && rm /var/www/html/my-zip-file*.zip && mv my-zip-file*.zip /var/www/html && cd
sudo crontab -e
@daily sh /usr/scripts/create-zip.sh
Well.. it doesn't work. I think that the problem is something related with privileges because I get
file.txt copied in
/home/myuser , and also the zip is created. But then i can't get the zip moved to
/var/www/html, even if the crontab is running under Root privileges.
Also..since a .zip is created once a day, I'd need to remove the previous .zip from /var/www/html before move the new one in there. I tried using
rm /var/www/html my-zip-file-*.zip
(check the create-zip.sh above) but it doesn't work too.. so I guess it's something wrong with privileges. /var/www/html is into the group www-data and its owner too is www-data.