bash - 将 Xterm 的输出重定向到日志文件

标签 bash centos centos7 xterm

我一直没能找到这个问题的答案。 我在 xterm 中启动了三个程序用于演示自动化脚本。我需要记录 xterm 窗口的结果。现在,我的脚本如下所示:

#!/bin/bash/sh

echo "NOTE - THIS PROCESS TAKES APPROXIMATELY 60 SECONDS TO RUN"

    cd ~/myProject/ProgramOne
    xterm -e ProgramOne progone.config 2>&1 /tmp/logs/p1.txt &

    cd ~/myProject/ProgramTwo
    xterm -e ProgramOne progtwo.config 2>&1 /tmp/logs/p2.txt &

    cd ~/myProject/ProgramThree
    xterm -e ProgramOne progthree.config 2>&1 /tmp/logs/p3.txt &


# allow the scripts to collect data
sleep 60

# kill the xterm sessions from running since this is just a demonstration
pkill -9 xterm

echo "******************************************"
echo "START PROGRAMS SCRIPT COMPLETE"
echo "******************************************"   

我已验证 ~/myProject/ProgramOne~/myProject/ProgramTwo~/myProject/ProgramThree 都存在, /tmp/logs/*

文件已创建,它们只是没有任何内容,也不包含 xterm 窗口的输出,我可以看到弹出窗口有数百行信息。

最佳答案

命令中的以下更改有效:

xterm -e ProgramOne progone.config 2>&1 /tmp/logs/p1.txt &

xterm -e 'ProgramOne progone.config 2>&1 | tee /tmp/logs/p1.txt' &

关于bash - 将 Xterm 的输出重定向到日志文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52822448/

相关文章:

php - 更改用户组后在 centos 服务器上出现 403 Forbidden 错误

bash - 脚本在 '$ ssh bash script arg' 中看不到 arg

bash - Bash 中的命令替换为 tty

regex - 将文件名中除扩展名之外的所有 '.' 重命名为 '_'

linux - 在 CentOS 上暗恋时如何自动重启服务?

php - Linux 服务器上的内部服务器错误 (500) 和 PHP max_execution_time

docker - Sonarqube从7.4社区升级到7.9 JVM错误

bash - 在Docker中运行两个可执行文件

php - 使用 WHM 在 Centos 6.5 上的 AutoKill 过程

cross-compiling - 在 Centos 7 上交叉编译 Centos 6 系统