A
A
Andrey2016-01-07 19:41:04
bash
Andrey, 2016-01-07 19:41:04

Did I write the directory copy script correctly?

Hello!
We need a script that will archive the catalog with images by cron and send it to Yandex disk.
I never really worked with bash, I googled it as best I could!
1. Please see if everything was done correctly, point out the mistakes!?
2. As I understand there are many different shells bash, sh, etc., which one is better to use for everyday tasks?

#!/bin/bash

PATH_TO_MEDIA='/home/andrey/site_ru/project/media'
FILE_PATH="/tmp/$(date "+%Y-%m-%d_%H-%M-%S")_media.tar.gz"

echo "Архивирую медиа каталог \"$PATH_TO_MEDIA\".."
cd $(dirname $PATH_TO_MEDIA)
tar czf $FILE_PATH --exclude='.*' --exclude='cache' $(basename $PATH_TO_MEDIA)
echo "Готово!"

echo "Отправляю на сервер.."
curl --user mail:123 -T "{$FILE_PATH}" https://webdav.yandex.ru/backup/media/
echo "Готово!"

exit 0

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
dpvpro, 2016-01-07
@dpvpro

Does he fulfill the task that you assign to him? So it's written correctly.

S
Sergey Sokolov, 2016-01-08
@freaks

On the second question, here is a pretty good article that compares popular shells.

V
Viktor Taran, 2016-01-11
@shambler81

not really cool, because $(date "+%Y-%m-%d_%H-%M-%S" will be different when creating an archive and sending. Because time is running out.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question