redirect script output from within the script to log file and screen at the same time
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I've been trying to redirect and append my script output from within the script to a log file and the screen at the same time. I've tried various guide I could find but none was successful.
My script looks something like this;
#!/bin/bash
log_file=/var/log/test.log
exec 2>&1 | tee -a $log_file
do something...
cleanup ()
do some cleanup...
int_handler()
echo "Interrupted."
cleanup
exit 1
trap 'int_handler' INT
read -r -p "Do you want continue the process now? [y|n] : " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])+$ ]]
then
do this...
exit 0
else
do that...
exit 0
fi
while true
do
sleep 1
done
exit 0
each time I run it, it appears that the redirection only capture the last screen output session.
Any help would be greatly appreciated.
Thanks in advance.
debian
add a comment |Â
up vote
0
down vote
favorite
I've been trying to redirect and append my script output from within the script to a log file and the screen at the same time. I've tried various guide I could find but none was successful.
My script looks something like this;
#!/bin/bash
log_file=/var/log/test.log
exec 2>&1 | tee -a $log_file
do something...
cleanup ()
do some cleanup...
int_handler()
echo "Interrupted."
cleanup
exit 1
trap 'int_handler' INT
read -r -p "Do you want continue the process now? [y|n] : " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])+$ ]]
then
do this...
exit 0
else
do that...
exit 0
fi
while true
do
sleep 1
done
exit 0
each time I run it, it appears that the redirection only capture the last screen output session.
Any help would be greatly appreciated.
Thanks in advance.
debian
What do you mean by "last screen output session"? A more minimal example would help. Also, readman stdbuf
.
â Ferenc Wágner
Sep 29 '17 at 15:00
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I've been trying to redirect and append my script output from within the script to a log file and the screen at the same time. I've tried various guide I could find but none was successful.
My script looks something like this;
#!/bin/bash
log_file=/var/log/test.log
exec 2>&1 | tee -a $log_file
do something...
cleanup ()
do some cleanup...
int_handler()
echo "Interrupted."
cleanup
exit 1
trap 'int_handler' INT
read -r -p "Do you want continue the process now? [y|n] : " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])+$ ]]
then
do this...
exit 0
else
do that...
exit 0
fi
while true
do
sleep 1
done
exit 0
each time I run it, it appears that the redirection only capture the last screen output session.
Any help would be greatly appreciated.
Thanks in advance.
debian
I've been trying to redirect and append my script output from within the script to a log file and the screen at the same time. I've tried various guide I could find but none was successful.
My script looks something like this;
#!/bin/bash
log_file=/var/log/test.log
exec 2>&1 | tee -a $log_file
do something...
cleanup ()
do some cleanup...
int_handler()
echo "Interrupted."
cleanup
exit 1
trap 'int_handler' INT
read -r -p "Do you want continue the process now? [y|n] : " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])+$ ]]
then
do this...
exit 0
else
do that...
exit 0
fi
while true
do
sleep 1
done
exit 0
each time I run it, it appears that the redirection only capture the last screen output session.
Any help would be greatly appreciated.
Thanks in advance.
debian
debian
edited Sep 29 '17 at 14:57
Ferenc Wágner
2,774920
2,774920
asked Sep 25 '17 at 22:38
user3289583
1
1
What do you mean by "last screen output session"? A more minimal example would help. Also, readman stdbuf
.
â Ferenc Wágner
Sep 29 '17 at 15:00
add a comment |Â
What do you mean by "last screen output session"? A more minimal example would help. Also, readman stdbuf
.
â Ferenc Wágner
Sep 29 '17 at 15:00
What do you mean by "last screen output session"? A more minimal example would help. Also, read
man stdbuf
.â Ferenc Wágner
Sep 29 '17 at 15:00
What do you mean by "last screen output session"? A more minimal example would help. Also, read
man stdbuf
.â Ferenc Wágner
Sep 29 '17 at 15:00
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f394424%2fredirect-script-output-from-within-the-script-to-log-file-and-screen-at-the-same%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
What do you mean by "last screen output session"? A more minimal example would help. Also, read
man stdbuf
.â Ferenc Wágner
Sep 29 '17 at 15:00