【问题标题】:Redirecting output for find & exec to a log file将 find 和 exec 的输出重定向到日志文件
【发布时间】:2020-11-17 18:53:11
【问题描述】:

我根据以下参考创建了一个用于移动文件的脚本。我正在尝试捕获从源移动到目标的所有文件活动以及任何不成功的文件。 我尝试将输出输出到日志文件,但操作后日志文件大小为 0。请问有什么建议吗?

参考文档# https://unix.stackexchange.com/questions/59112/preserve-directory-structure-when-moving-files-using-find

下面是代码块

destination=$(cd -- "$destination" && pwd)
cd -- "$source" &&
find . -type f -newermt $startdays -not -newermt $enddays -exec sh -c '
  for x do
    mkdir -p "$0/${x%/*}"
    mv "$x" "$0/$x"
  done
' "$destination" {} + >> output.log

【问题讨论】:

    标签: linux shell unix output


    【解决方案1】:

    默认情况下,mv 不会产生任何输出。如果您希望它产生输出,请尝试mv -v

    【讨论】:

    • 谢谢,效果很好。当我运行我的脚本 test1.sh 时,它会在控制台上打印出 mv:cannot move messages for unsuccessful files (: Permission denied) 。我也想将这些拒绝文件捕获到单独的日志文件中。我正在考虑编写一个包装外壳 Main.sh 并从中调用 test1.sh 并将其输出重定向到另一个日志文件。有更好的建议吗?
    • 只需重定向标准错误:find ... >> output.log 2>&1
    猜你喜欢
    • 2016-10-07
    • 1970-01-01
    • 2019-03-20
    • 1970-01-01
    • 2012-03-01
    • 2013-04-15
    • 2010-09-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多