【问题标题】:Output redirection in a bash script doesn't workbash 脚本中的输出重定向不起作用
【发布时间】:2012-09-29 06:01:27
【问题描述】:

我有一个脚本可以确保进程继续运行,并且进程的输出被重定向到相应的 process_name.out 文件。

奇怪的是(至少对我而言),输出不会被重定向到文件,除非我关闭了脚本,尽管错误确实如此。

这方面的任何线索都会很有帮助。

#!/bin/bash

until $1 >> "/root/$1.out" 2>>"/root/$1.log" ; do
    echo "Server $1 crashed with exit code $?.  Respawning.." >> "/root/procees.log"
    sleep 1
done

【问题讨论】:

  • 你没有遭受表单缓冲的困扰吗?
  • 试试until unbuffer $1 ... 祝你好运。
  • @shelter 谢谢,安装必要的软件包后它可以工作。
  • 你能把它作为答案,shellter 或 w2lame 吗?目前,这被列为未回答的问题。

标签: bash outputstream fileoutputstream


【解决方案1】:

@shelter 在其中一个 cmets 中提到的解决方案是使用

until unbuffer $1

改为

【讨论】:

    猜你喜欢
    • 2014-11-17
    • 1970-01-01
    • 2020-03-22
    • 1970-01-01
    • 1970-01-01
    • 2014-01-04
    • 1970-01-01
    • 2012-08-22
    • 1970-01-01
    相关资源
    最近更新 更多