Unable to redirect output to file from certain commands

The name of the pictureThe name of the pictureThe name of the pictureClash 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 is
RTNETLINK 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.254which is expected in those conditions










share|improve this question





















  • 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














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 is
RTNETLINK 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.254which is expected in those conditions










share|improve this question





















  • 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












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 is
RTNETLINK 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.254which is expected in those conditions










share|improve this question













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 is
RTNETLINK 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.254which is expected in those conditions







linux shell-script networking io-redirection raspbian






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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
















  • 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










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





share|improve this answer






















  • 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










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















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






























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





share|improve this answer






















  • 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














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





share|improve this answer






















  • 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












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





share|improve this answer














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






share|improve this answer














share|improve this answer



share|improve this answer








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
















  • 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

















 

draft saved


draft discarded















































 


draft saved


draft discarded














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













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay