Unable to redirect output to file from certain commands
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I'm trying to write the output (error or success) to a file. With other commands I can do this without issue however the below commands will only write to the terminal but not to a file. If I run directly in the terminal I can see the output on the screen and the file's will be created but will be empty.
The commands are
sudo ip r add default via 192.168.1.254 > outfile.txt >&1
sudo ip r add default via 192.168.1.254 | tee -a outfile.txt
sudo /sbin/route add default gw 192.168.1.254 | sudo tee -a outfile.txt
These are going in a boot script (headless setup). I'm not able to simulate the boot conditions from within the terminal directly so just running them directly doesn't necessarily give me the output that happens in boot conditions meaning I can't work out why/whats causing them to fail.
The output when I run directly in the terminal isRTNETLINK answers: Network is unreachable
for sudo ip r add default via 192.168.1.254
and SIOCADDRT: Network is unreachable
for sudo route add default gw 192.168.1.254
which is expected in those conditions
linux shell-script networking io-redirection raspbian
add a comment |Â
up vote
0
down vote
favorite
I'm trying to write the output (error or success) to a file. With other commands I can do this without issue however the below commands will only write to the terminal but not to a file. If I run directly in the terminal I can see the output on the screen and the file's will be created but will be empty.
The commands are
sudo ip r add default via 192.168.1.254 > outfile.txt >&1
sudo ip r add default via 192.168.1.254 | tee -a outfile.txt
sudo /sbin/route add default gw 192.168.1.254 | sudo tee -a outfile.txt
These are going in a boot script (headless setup). I'm not able to simulate the boot conditions from within the terminal directly so just running them directly doesn't necessarily give me the output that happens in boot conditions meaning I can't work out why/whats causing them to fail.
The output when I run directly in the terminal isRTNETLINK answers: Network is unreachable
for sudo ip r add default via 192.168.1.254
and SIOCADDRT: Network is unreachable
for sudo route add default gw 192.168.1.254
which is expected in those conditions
linux shell-script networking io-redirection raspbian
Please check the gw 192.168.1.254 reachability from your server
â EBIN GLADSON
Sep 25 at 10:11
That's what I'm trying to work out. The script is about detecting a gateway change so the old one isn't accessible but the new one (added from a list) should be however it's not adding the new one for some reason so I needed to work out what error it's coming back when it's running during the boot process when trying to add the new one.
â Josh
Sep 25 at 10:14
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm trying to write the output (error or success) to a file. With other commands I can do this without issue however the below commands will only write to the terminal but not to a file. If I run directly in the terminal I can see the output on the screen and the file's will be created but will be empty.
The commands are
sudo ip r add default via 192.168.1.254 > outfile.txt >&1
sudo ip r add default via 192.168.1.254 | tee -a outfile.txt
sudo /sbin/route add default gw 192.168.1.254 | sudo tee -a outfile.txt
These are going in a boot script (headless setup). I'm not able to simulate the boot conditions from within the terminal directly so just running them directly doesn't necessarily give me the output that happens in boot conditions meaning I can't work out why/whats causing them to fail.
The output when I run directly in the terminal isRTNETLINK answers: Network is unreachable
for sudo ip r add default via 192.168.1.254
and SIOCADDRT: Network is unreachable
for sudo route add default gw 192.168.1.254
which is expected in those conditions
linux shell-script networking io-redirection raspbian
I'm trying to write the output (error or success) to a file. With other commands I can do this without issue however the below commands will only write to the terminal but not to a file. If I run directly in the terminal I can see the output on the screen and the file's will be created but will be empty.
The commands are
sudo ip r add default via 192.168.1.254 > outfile.txt >&1
sudo ip r add default via 192.168.1.254 | tee -a outfile.txt
sudo /sbin/route add default gw 192.168.1.254 | sudo tee -a outfile.txt
These are going in a boot script (headless setup). I'm not able to simulate the boot conditions from within the terminal directly so just running them directly doesn't necessarily give me the output that happens in boot conditions meaning I can't work out why/whats causing them to fail.
The output when I run directly in the terminal isRTNETLINK answers: Network is unreachable
for sudo ip r add default via 192.168.1.254
and SIOCADDRT: Network is unreachable
for sudo route add default gw 192.168.1.254
which is expected in those conditions
linux shell-script networking io-redirection raspbian
linux shell-script networking io-redirection raspbian
asked Sep 25 at 9:45
Josh
51
51
Please check the gw 192.168.1.254 reachability from your server
â EBIN GLADSON
Sep 25 at 10:11
That's what I'm trying to work out. The script is about detecting a gateway change so the old one isn't accessible but the new one (added from a list) should be however it's not adding the new one for some reason so I needed to work out what error it's coming back when it's running during the boot process when trying to add the new one.
â Josh
Sep 25 at 10:14
add a comment |Â
Please check the gw 192.168.1.254 reachability from your server
â EBIN GLADSON
Sep 25 at 10:11
That's what I'm trying to work out. The script is about detecting a gateway change so the old one isn't accessible but the new one (added from a list) should be however it's not adding the new one for some reason so I needed to work out what error it's coming back when it's running during the boot process when trying to add the new one.
â Josh
Sep 25 at 10:14
Please check the gw 192.168.1.254 reachability from your server
â EBIN GLADSON
Sep 25 at 10:11
Please check the gw 192.168.1.254 reachability from your server
â EBIN GLADSON
Sep 25 at 10:11
That's what I'm trying to work out. The script is about detecting a gateway change so the old one isn't accessible but the new one (added from a list) should be however it's not adding the new one for some reason so I needed to work out what error it's coming back when it's running during the boot process when trying to add the new one.
â Josh
Sep 25 at 10:14
That's what I'm trying to work out. The script is about detecting a gateway change so the old one isn't accessible but the new one (added from a list) should be however it's not adding the new one for some reason so I needed to work out what error it's coming back when it's running during the boot process when trying to add the new one.
â Josh
Sep 25 at 10:14
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
For bash
ip r add default via 192.168.1.254 &> outfile.txt
or the standard form for other shells:
ip r add default via 192.168.1.254 >outfile.txt 2>&1
from man bash
:
Redirecting Standard Output and Standard Error
This construct allows both the standard output (file descriptor 1) and
the standard error output (file descriptor 2) to be redirected to the
file whose name is the expansion of word.
There are two formats for redirecting standard output and standard erâÂÂ
ror:
&>word
and
>&word
Of the two forms, the first is preferred. This is semantically equivaâÂÂ
lent to
>word 2>&1
hmm I thought I had tried that yesterday - must have been tired.&>word
worked - at least in the terminal. I'll try in the boot script shortly.
â Josh
Sep 25 at 9:52
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
For bash
ip r add default via 192.168.1.254 &> outfile.txt
or the standard form for other shells:
ip r add default via 192.168.1.254 >outfile.txt 2>&1
from man bash
:
Redirecting Standard Output and Standard Error
This construct allows both the standard output (file descriptor 1) and
the standard error output (file descriptor 2) to be redirected to the
file whose name is the expansion of word.
There are two formats for redirecting standard output and standard erâÂÂ
ror:
&>word
and
>&word
Of the two forms, the first is preferred. This is semantically equivaâÂÂ
lent to
>word 2>&1
hmm I thought I had tried that yesterday - must have been tired.&>word
worked - at least in the terminal. I'll try in the boot script shortly.
â Josh
Sep 25 at 9:52
add a comment |Â
up vote
0
down vote
accepted
For bash
ip r add default via 192.168.1.254 &> outfile.txt
or the standard form for other shells:
ip r add default via 192.168.1.254 >outfile.txt 2>&1
from man bash
:
Redirecting Standard Output and Standard Error
This construct allows both the standard output (file descriptor 1) and
the standard error output (file descriptor 2) to be redirected to the
file whose name is the expansion of word.
There are two formats for redirecting standard output and standard erâÂÂ
ror:
&>word
and
>&word
Of the two forms, the first is preferred. This is semantically equivaâÂÂ
lent to
>word 2>&1
hmm I thought I had tried that yesterday - must have been tired.&>word
worked - at least in the terminal. I'll try in the boot script shortly.
â Josh
Sep 25 at 9:52
add a comment |Â
up vote
0
down vote
accepted
up vote
0
down vote
accepted
For bash
ip r add default via 192.168.1.254 &> outfile.txt
or the standard form for other shells:
ip r add default via 192.168.1.254 >outfile.txt 2>&1
from man bash
:
Redirecting Standard Output and Standard Error
This construct allows both the standard output (file descriptor 1) and
the standard error output (file descriptor 2) to be redirected to the
file whose name is the expansion of word.
There are two formats for redirecting standard output and standard erâÂÂ
ror:
&>word
and
>&word
Of the two forms, the first is preferred. This is semantically equivaâÂÂ
lent to
>word 2>&1
For bash
ip r add default via 192.168.1.254 &> outfile.txt
or the standard form for other shells:
ip r add default via 192.168.1.254 >outfile.txt 2>&1
from man bash
:
Redirecting Standard Output and Standard Error
This construct allows both the standard output (file descriptor 1) and
the standard error output (file descriptor 2) to be redirected to the
file whose name is the expansion of word.
There are two formats for redirecting standard output and standard erâÂÂ
ror:
&>word
and
>&word
Of the two forms, the first is preferred. This is semantically equivaâÂÂ
lent to
>word 2>&1
edited Sep 25 at 9:56
answered Sep 25 at 9:49
Ipor Sircer
9,3981920
9,3981920
hmm I thought I had tried that yesterday - must have been tired.&>word
worked - at least in the terminal. I'll try in the boot script shortly.
â Josh
Sep 25 at 9:52
add a comment |Â
hmm I thought I had tried that yesterday - must have been tired.&>word
worked - at least in the terminal. I'll try in the boot script shortly.
â Josh
Sep 25 at 9:52
hmm I thought I had tried that yesterday - must have been tired.
&>word
worked - at least in the terminal. I'll try in the boot script shortly.â Josh
Sep 25 at 9:52
hmm I thought I had tried that yesterday - must have been tired.
&>word
worked - at least in the terminal. I'll try in the boot script shortly.â Josh
Sep 25 at 9:52
add a comment |Â
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%2f471278%2funable-to-redirect-output-to-file-from-certain-commands%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
Please check the gw 192.168.1.254 reachability from your server
â EBIN GLADSON
Sep 25 at 10:11
That's what I'm trying to work out. The script is about detecting a gateway change so the old one isn't accessible but the new one (added from a list) should be however it's not adding the new one for some reason so I needed to work out what error it's coming back when it's running during the boot process when trying to add the new one.
â Josh
Sep 25 at 10:14