Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

logging to file gnome-terminal output

I have a bash script where I use

gnome-terminal -e /folder/script1 &
gnome-terminal -e /folder/script2 &

to open two new terminals and carry out two parallel jobs.

I want to know if it is possible to log the output of these scripts by using something like

gnome-terminal -e /folder/script1 2>&1 | tee script1.log

Thank you.

like image 210
Kynikos Avatar asked Feb 22 '23 13:02

Kynikos


1 Answers

Try:

gnome-terminal -e 'bash -c "/folder/script1 2>&1 | tee /tmp/script1.log"'

Explanation:

gnome-terminal -e /folder/script1 2>&1

opens a gnome-terminal, executes /folder/script1, and directs stderr of the gnome-terminal command to stdout. To redirect stderr of script1 to stdout, we need a shell. The same goes for | tee /tmp/script1.log.

like image 74
unutbu Avatar answered Mar 03 '23 23:03

unutbu