Pergunta

I have this issue with a simple bash script to create a file and then log to it the output of rsync.

However, it does not work I keep getting "command not found", does not create the file and does not log to it. I get the error "/var/log/" is a directory.

#!/bin/bash
FILENAME=ram_sys4-$(date +%Y_%m_%d_%H:%M).log
touch /var/log/$(FILENAME)
date >> /var/log/$(FILENAME)
rsync -r -L -H -g -o -p -t -a --delete --verbose --log-format="%t %i %l %f %M %h %o \n" --log-file=/var/log/$(FILENAME) /root/Desktop/R/ /root/Desktop/W/
date >> /var/log/$(FILENAME)
Foi útil?

Solução

The syntax $(VAR_NAME) is used in Makefiles, but not in bash. In bash, use

${VAR_NAME}

or even simpler

$VAR_NAME

Outras dicas

#!/bin/bash
FILENAME=ram_sys4-$(date +%Y_%m_%d_%H:%M).log
touch /var/log/${FILENAME}
date >> /var/log/${FILENAME}
rsync -r -L -H -g -o -p -t -a --delete --verbose --log-format="%t %i %l %f %M %h %o \n" --log-file=/var/log/${FILENAME} /root/Desktop/R/ /root/Desktop/W/
date >> /var/log/${FILENAME}

$(FILENAME) is Command Substitution what you are trying do to is Parameter Expansion

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top