Search code examples
bashcentoscentos7xterm

Redirect output of Xterm to log file


I have not been able to find an answer to this problem. I have three programs kicked off in xterm for a demonstration automation script. I need to log the results of the xterm windows. Right now, my script looks as follows:

#!/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 "******************************************"   

I have verified that ~/myProject/ProgramOne and ~/myProject/ProgramTwo and ~/myProject/ProgramThree all exist, as does /tmp/logs/*

The files get created, they just simply have nothing in them and do NOT contain the output of the xterm windows, which I can see popup with hundreds of lines of information.


Solution

  • The following change in the command worked:

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

    to

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