我正在重写一个简单的脚本,CopyScript.sh
这是我几年前写的,用于将内容从我的 NAS 复制到 USB 磁盘。
#!/bin/bash
SYNCPATH="/volume1/"
SYNCPATHTO="/volumeUSB1/usbshare/synology-may-2015-bak/"
NAMELOG="/volume1/homes/sando/logrsync.log"
echo "${NAMELOG}"
date >"${NAMELOG}"
rsync --verbose --recursive --size-only --exclude-from 'exclude-list.txt' $SYNCPATH $SYNCPATHTO >> $NAMELOG 2>&1
date >> "${NAMELOG}"
echo DONE >> "${NAMELOG}"
但是,当我执行时,bash CopyScript.sh
出现以下错误:“模糊重定向:第 7 行:1”
确实,当我查看文件系统中的文件时,我看到 2 个名为 logrsync.log 的日志文件,一个为 1 kB,另一个为 0 kB。我知道这会导致重定向不明确,但为什么会有两个文件?我相信在我的旧系统上,非常相似的代码可以正常工作。我遗漏了什么?
干杯,桑多
答案1
尝试将 NAMELOG 变量放在 rsync 重定向中的引号内,即“${NAMELOG}”
答案2
您正在尝试将 rsync 活动写入日志文件
但这不是通过重定向>>来实现的,而是通过一些参数来实现的。
--log-file=FILE override the "log file" setting
--log-file-format=FMT override the "log format" setting
**--log-file=FIL**E This option causes rsync to log what it is doing to a file. This is similar to the logging that a daemon does, but can be requested for the client side and/or the server side of a non-daemon transfer. If specified as a client option, transfer logging will be enabled with a default format of "%i %n%L". See the
**--log-file-format** option if you wish to override this.
**--log-file-format=FORMAT** This allows you to specify exactly what per-update logging is put into the file specified by the --log-file option (which must also be specified for this option to have any effect). If you specify an empty string, updated files will not be mentioned in the log file. For a list of the possible escape characters, see the "log format" setting in the rsyncd.conf manpage. The default FORMAT used if --log-file is specified and this option is not is ’%i %n%L’.
所以我应该尝试这个:
rsync --verbose --recursive --size-only --exclude-from 'exclude-list.txt' --log-file=$NAMELOG $SYNCPATH $SYNCPATHTO