Kynikos
Kynikos

Reputation: 69

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.

Upvotes: 4

Views: 4465

Answers (2)

onzyone
onzyone

Reputation: 78

you can try something like this as well close to the top of the script that you are calling. This way you will not have to | tee

exec >> ${LOGNAME} 2>&1

Upvotes: 1

unutbu
unutbu

Reputation: 879251

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.

Upvotes: 7

Related Questions