I am using the following command to open a terminal and execute an script. How to save the output to a log file.
gnome-terminal -x bash -c "print1.py; read -n1" &I tried following options but didn't succeed. Kindly suggest a solution.
gnome-terminal -x bash -c "print1.py; read -n1" & > log.txt
gnome-terminal -x bash -c "print1.py; read -n1" & | tee log.txt
gnome-terminal -x bash -c "print1.py; read -n1" & | tee -a log.txt 2 Answers
Assuming the read is just for interactivity, try saving the output inside the bash command:
gnome-terminal -x bash -c "print1.py | tee log.txt; read -n1" & 1 Just use script to save all the output to a file.
[morris@rhel tmp]$ script output.log
Script started, file is output.log
[morris@rhel tmp]$ uname -r
3.10.0-514.21.1.el7.x86_64
[morris@rhel tmp]$ exit
Script done, file is output.log
[morris@rhel tmp]$ cat output.log
Script started on Sun 18 Jun 2017 06:55:39 PM HKT
[morris@rhel tmp]$ uname -r
3.10.0-514.21.1.el7.x86_64
[morris@rhel tmp]$ exit
Script done on Sun 18 Jun 2017 06:55:48 PM HKT
[morris@rhel tmp]$ with gnome-terminal, something like bellow may work.
gnome-terminal -x bash -c "script -c 'print1.py; read -n1' output.log; who -a;" & 2