Home > Software engineering >  register rsync in shellscript
register rsync in shellscript

Time:02-01

What should I add so that my little script logs the rsync command only if it contains files to copy and is not every 5 minutes logging nothing.

#!/bin/bash
#Sincronizar directorios de Transferencia.

#Local
ORIGEN=/home/sftp/Recepcion/
DESTINO=/mnt/Recepcion/

Fecha_Y_Hora=`date " %d-%m-%y_%H-%M-%S"`
RUTA_LOG="/opt/rundeck/commands/rsync.txt"

echo "[$Fecha_Y_Hora] Comenzando Sincronizacion ..." >> $RUTA_LOG
rsync -vr --times $ORIGEN $DESTINO >> $RUTA_LOG

Greetings

CodePudding user response:

To check for files you can try something like this:

rsync -avunc --delete $ORIGEN $DESTINO | grep "^deleting" | wc -l

If the result is greater than 0, there are files.

  •  Tags:  
  • Related