【问题标题】:Bash scripting rsync: rsync: link_stat (blah) failed: No such file or directory (2)Bash 脚本 rsync: rsync: link_stat (blah) failed: No such file or directory (2)
【发布时间】:2012-05-30 08:56:51
【问题描述】:

我正在尝试为我的本地 (Mac OS X) 机器编写一个简单的 bash 脚本,以将文件从我机器上的目录移动到远程机器。此行失败:

rsync --verbose  --progress --stats --compress --rsh=ssh \
      --recursive --times --perms --links --delete \
      --exclude "*bak" --exclude "*~" \
      /repository/* $DEV_SERVER:$REMOTE_DIR

$DEV_SERVER$REMOTE_DIR 是之前定义的,我回应它们以验证它们是否准确。

我得到的错误是:

rsync: link_stat /Users/myusername/mycurrentdirectory failed: No such file or directory (2)

这里要注意的是,它使用的是我的工作目录,而不是使用定义的目录(/repository,它位于机器的根目录中)。这是什么原因造成的?

【问题讨论】:

  • 请引用你的变量!

标签: bash scripting rsync


【解决方案1】:

我在做一些 rsync 工作时遇到了同样的错误。我有错误的字符来指定我必须从其他地方复制和粘贴命令得到的选项:

而不是下面的正确字符:

-

【讨论】:

    【解决方案2】:

    检查您的\ 字符是否在行尾没有空格。这将导致 BASH 无法正确解释换行,从而出现上述 rsync 错误。

    【讨论】:

    • 在我的例子中,当 rsync -e 选项提供了一个空字符串或一个空格字符并且目标文件(要同步的)不存在时,就会发生这个错误。 (-e 选项值是有条件地确定的)。
    【解决方案3】:

    从源位置删除'*',如果你在最后指定'/',rsync 知道在目录内部查找

    这样:

    rsync --verbose  --progress --stats --compress --rsh=ssh --recursive --times --perms --links --delete --exclude "*bak" --exclude "*~" /repository/ $DEV_SERVER:$REMOTE_DIR
    

    【讨论】:

      【解决方案4】:

      这个:

      rsync --verbose  --progress --stats --compress --rsh=ssh \
        --recursive --times --perms --links --delete \
        --exclude "*bak" --exclude "*~" \
        /repository/* $DEV_SERVER:$REMOTE_DIR
      

      应该是这样的:

      rsync --verbose  --progress --stats --compress --rsh=ssh --recursive --times --perms --links --delete --exclude "*bak" --exclude "*~" /repository/* $DEV_SERVER:$REMOTE_DIR
      

      Bash 对 \ 字符的解释与命令行不同,或者后面可能有一个隐含的非空白字符。

      【讨论】:

      • bash 在非交互式会话中如何以不同方式处理它?
      • 更适合 superuser.com
      • 我在使用 line-continuation-char 时遇到的唯一问题(即`), on cmd-line OR in a script, is when there is any character besides a \n` 后面的字符。我没有否决您的答案,但我认为不是对。祝大家好运。
      • @sputnick 这确实是基于问题的评论,而不是基于回复的评论,尽管完全有效。
      • 这是完全错误的。 Bash 解释脚本的方式与解释命令提示符输入的方式完全相同。