/
jenyapng
/
project-bash
Обзор
Документация
Войти
/
jenyapng
/
project-bash
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
task-2/script-30.sh
43 строки
1 KB
jenyapng
first_commit
11 авг 2026, 16:22
11 авг 2026, 16:22
9ea1476
Код
Авторство
О чём код?
#!/bin/bash target_dir=${1:-.} archive_name=${2:-archive.tar} if [ ! -d "$target_dir" ]; then echo "Ошибка: Директория '$target_dir' не существует" >&2 exit 1 fi if [ ! -f "$archive_name" ]; then echo "Создание нового архива: $archive_name" tar -cf "$archive_name" -C "$target_dir" . exit 0 fi temp_file=$(mktemp) while IFS= read -r -d '' file; do archived_date=$(tar -tvf "$archive_name" "$file" 2>/dev/null | awk '{print $4" "$5" "$6}') if [ -z "$archived_date" ]; then echo "Добавлен новый файл: $file" echo "$file" >> "$temp_file" else current_date=$(date -r "$target_dir/$file" "+%Y-%m-%d %H:%M") archived_timestamp=$(date -d "$archived_date" "+%Y-%m-%d %H:%M") if [ "$current_date" != "$archived_timestamp" ]; then echo "Обновлён файл: $file (было: $archived_date, стало: $current_date)" echo "$file" >> "$temp_file" fi fi done < <(find "$target_dir" -type f -print0) if [ -s "$temp_file" ]; then echo "Обновление архива..." tar -uf "$archive_name" -C "$target_dir" -T "$temp_file" else echo "Нет изменений - архив актуален" fi rm -f "$temp_file"