Localizar arquivos e tar.gz a lista resultante

3

A execução do seguinte comando funciona conforme o esperado:

find /path/to/logs/ \( -type f -name '*20161005.log' \) -print0 | tar -czvf /path/to/backups/backup_logs_20161005.tar.gz --null -T -

Mas, tentando usar isso em um script bash, recebo um arquivo .tar.gz vazio:

#!/bin/bash
now="$(date)"
printf "Current date and time: $now"

## working paths
LOGSPATH="/path/to/logs/"
BACKPATH="/path/to/backups/"

## date to work with
DATETIME='date -d "yesterday 13:00 " '+%Y%m%d''

## find files matching the working date and .tar.gz the result
printf "\nStarting yesterday logs backup, please wait..."
find "$LOGSPATH" \( -type f -name '*"$DATETIME".log' \) -print0 | tar -czvf "$BACKPATH"backup_logs_"$DATETIME".tar.gz --null -T -
printf "\ndone!"

## delete backup files
printf "\nRemoving logs from yesterday..."
find "$LOGSPATH" -type f -name '*"$DATETIME".log' -delete
printf "\ndone!\n"

Saída:

Current date and time: Thu Oct 6 16:14:29 WEST 2016
Starting yesterday logs backup, please wait...
done!
Removing logs from yesterday...
done!

O que eu sinto falta ao colocar esse comando em um script bash?

    
por Zuul 06.10.2016 / 17:21

1 resposta

3

Substituir

-name '*"$DATETIME".log'

com

-name "*$DATETIME.log"

As aspas simples são muito strongs, as aspas duplas permitem $ VARIABLE dentro.

    
por 06.10.2016 / 17:33