nohup output redirection to a different file
I use nohup
quite often for important long running processes under linux
/bash
, so much so that nohup time my command with arguments && mv nohup.out my.log
is almost an idiom for me.
The problem is that nohup
puts both stdout
and stderr
into nohup.out
, and I cannot control the name of the file. This means that if I accidentally start two nohup
s in the same directory, their output will be interleaved in nohup.out
.
The questions are:
How do I deal with this problem? Always running
nohup
s in separate directories and writing a shell function which will first check for./nohup.out
are two sucky options I see.How come I cannot tell
nohup
where to redirect the output? GNU tools tend to have so many options, why notnohup
?
bash nohup
add a comment |
I use nohup
quite often for important long running processes under linux
/bash
, so much so that nohup time my command with arguments && mv nohup.out my.log
is almost an idiom for me.
The problem is that nohup
puts both stdout
and stderr
into nohup.out
, and I cannot control the name of the file. This means that if I accidentally start two nohup
s in the same directory, their output will be interleaved in nohup.out
.
The questions are:
How do I deal with this problem? Always running
nohup
s in separate directories and writing a shell function which will first check for./nohup.out
are two sucky options I see.How come I cannot tell
nohup
where to redirect the output? GNU tools tend to have so many options, why notnohup
?
bash nohup
add a comment |
I use nohup
quite often for important long running processes under linux
/bash
, so much so that nohup time my command with arguments && mv nohup.out my.log
is almost an idiom for me.
The problem is that nohup
puts both stdout
and stderr
into nohup.out
, and I cannot control the name of the file. This means that if I accidentally start two nohup
s in the same directory, their output will be interleaved in nohup.out
.
The questions are:
How do I deal with this problem? Always running
nohup
s in separate directories and writing a shell function which will first check for./nohup.out
are two sucky options I see.How come I cannot tell
nohup
where to redirect the output? GNU tools tend to have so many options, why notnohup
?
bash nohup
I use nohup
quite often for important long running processes under linux
/bash
, so much so that nohup time my command with arguments && mv nohup.out my.log
is almost an idiom for me.
The problem is that nohup
puts both stdout
and stderr
into nohup.out
, and I cannot control the name of the file. This means that if I accidentally start two nohup
s in the same directory, their output will be interleaved in nohup.out
.
The questions are:
How do I deal with this problem? Always running
nohup
s in separate directories and writing a shell function which will first check for./nohup.out
are two sucky options I see.How come I cannot tell
nohup
where to redirect the output? GNU tools tend to have so many options, why notnohup
?
bash nohup
bash nohup
edited Feb 8 at 15:15
sds
asked Feb 14 '13 at 15:38
sdssds
1,24521430
1,24521430
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
You can redirect both stdout and stderr to one file. With Bash 4 (or others such as Zsh), as easy as:
nohup <some-command> &> output.log
I can't tell you why there's no separate option for nohup
to set the output, but if your shell can take care of that, you don't really need an option.
Will it preventnohup
from performing its own redirection?
– grawity
Feb 14 '13 at 15:45
1
GNUnohup
says that it'll redirect stdout to a file if you specifynohup command > file
. BSDnohup
doesn't mention this at all, but it worked for me.
– slhck
Feb 14 '13 at 15:50
GNU nohup says that it'll redirect stdout to a file if you specifynohup command > file
Isn't redirection in case ofnohup command > file
being handled by shell and notnohup
? If so then how cannohup
take any action based on weather redirection is present or not?
– Piotr Dobrogost
Jan 21 '15 at 8:29
The filenohup.out
will be created in the case of error output, too; but if you redirect both stdout and stderr, there cannot be any output, so the file will not be created. But the&>
syntax is not POSIX-compliant; you're better off with the answer by Irshad Khan elsewhere on this page.
– tripleee
Apr 20 '18 at 7:14
add a comment |
To Append output in user defined file you can use >>
in nohup command.
nohup php your_command >> filename.out 2>&1 &
This command will append all output in your file without removing old data.
1
And if you want to overwrite the output file using POSIXsh
syntax, that's simplynohup your_command >filename.out 2>&1 &
– tripleee
Apr 20 '18 at 7:15
add a comment |
There are more ways than just nohup
to start a process so that it would ignore SIGHUP; for example: (written as shell functions)
nohup() {
setsid "$@"
}
nohup() {
("$@" &)
}
nohup() {
"$@" & disown
}
(setsid
, or even (setsid "$@" &)
, might be the best choice.)
All of them allow you to specify your own redirections with >
, 2>
, and &>
/>&
.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
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',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f552133%2fnohup-output-redirection-to-a-different-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can redirect both stdout and stderr to one file. With Bash 4 (or others such as Zsh), as easy as:
nohup <some-command> &> output.log
I can't tell you why there's no separate option for nohup
to set the output, but if your shell can take care of that, you don't really need an option.
Will it preventnohup
from performing its own redirection?
– grawity
Feb 14 '13 at 15:45
1
GNUnohup
says that it'll redirect stdout to a file if you specifynohup command > file
. BSDnohup
doesn't mention this at all, but it worked for me.
– slhck
Feb 14 '13 at 15:50
GNU nohup says that it'll redirect stdout to a file if you specifynohup command > file
Isn't redirection in case ofnohup command > file
being handled by shell and notnohup
? If so then how cannohup
take any action based on weather redirection is present or not?
– Piotr Dobrogost
Jan 21 '15 at 8:29
The filenohup.out
will be created in the case of error output, too; but if you redirect both stdout and stderr, there cannot be any output, so the file will not be created. But the&>
syntax is not POSIX-compliant; you're better off with the answer by Irshad Khan elsewhere on this page.
– tripleee
Apr 20 '18 at 7:14
add a comment |
You can redirect both stdout and stderr to one file. With Bash 4 (or others such as Zsh), as easy as:
nohup <some-command> &> output.log
I can't tell you why there's no separate option for nohup
to set the output, but if your shell can take care of that, you don't really need an option.
Will it preventnohup
from performing its own redirection?
– grawity
Feb 14 '13 at 15:45
1
GNUnohup
says that it'll redirect stdout to a file if you specifynohup command > file
. BSDnohup
doesn't mention this at all, but it worked for me.
– slhck
Feb 14 '13 at 15:50
GNU nohup says that it'll redirect stdout to a file if you specifynohup command > file
Isn't redirection in case ofnohup command > file
being handled by shell and notnohup
? If so then how cannohup
take any action based on weather redirection is present or not?
– Piotr Dobrogost
Jan 21 '15 at 8:29
The filenohup.out
will be created in the case of error output, too; but if you redirect both stdout and stderr, there cannot be any output, so the file will not be created. But the&>
syntax is not POSIX-compliant; you're better off with the answer by Irshad Khan elsewhere on this page.
– tripleee
Apr 20 '18 at 7:14
add a comment |
You can redirect both stdout and stderr to one file. With Bash 4 (or others such as Zsh), as easy as:
nohup <some-command> &> output.log
I can't tell you why there's no separate option for nohup
to set the output, but if your shell can take care of that, you don't really need an option.
You can redirect both stdout and stderr to one file. With Bash 4 (or others such as Zsh), as easy as:
nohup <some-command> &> output.log
I can't tell you why there's no separate option for nohup
to set the output, but if your shell can take care of that, you don't really need an option.
answered Feb 14 '13 at 15:44
slhckslhck
162k47448471
162k47448471
Will it preventnohup
from performing its own redirection?
– grawity
Feb 14 '13 at 15:45
1
GNUnohup
says that it'll redirect stdout to a file if you specifynohup command > file
. BSDnohup
doesn't mention this at all, but it worked for me.
– slhck
Feb 14 '13 at 15:50
GNU nohup says that it'll redirect stdout to a file if you specifynohup command > file
Isn't redirection in case ofnohup command > file
being handled by shell and notnohup
? If so then how cannohup
take any action based on weather redirection is present or not?
– Piotr Dobrogost
Jan 21 '15 at 8:29
The filenohup.out
will be created in the case of error output, too; but if you redirect both stdout and stderr, there cannot be any output, so the file will not be created. But the&>
syntax is not POSIX-compliant; you're better off with the answer by Irshad Khan elsewhere on this page.
– tripleee
Apr 20 '18 at 7:14
add a comment |
Will it preventnohup
from performing its own redirection?
– grawity
Feb 14 '13 at 15:45
1
GNUnohup
says that it'll redirect stdout to a file if you specifynohup command > file
. BSDnohup
doesn't mention this at all, but it worked for me.
– slhck
Feb 14 '13 at 15:50
GNU nohup says that it'll redirect stdout to a file if you specifynohup command > file
Isn't redirection in case ofnohup command > file
being handled by shell and notnohup
? If so then how cannohup
take any action based on weather redirection is present or not?
– Piotr Dobrogost
Jan 21 '15 at 8:29
The filenohup.out
will be created in the case of error output, too; but if you redirect both stdout and stderr, there cannot be any output, so the file will not be created. But the&>
syntax is not POSIX-compliant; you're better off with the answer by Irshad Khan elsewhere on this page.
– tripleee
Apr 20 '18 at 7:14
Will it prevent
nohup
from performing its own redirection?– grawity
Feb 14 '13 at 15:45
Will it prevent
nohup
from performing its own redirection?– grawity
Feb 14 '13 at 15:45
1
1
GNU
nohup
says that it'll redirect stdout to a file if you specify nohup command > file
. BSD nohup
doesn't mention this at all, but it worked for me.– slhck
Feb 14 '13 at 15:50
GNU
nohup
says that it'll redirect stdout to a file if you specify nohup command > file
. BSD nohup
doesn't mention this at all, but it worked for me.– slhck
Feb 14 '13 at 15:50
GNU nohup says that it'll redirect stdout to a file if you specify
nohup command > file
Isn't redirection in case of nohup command > file
being handled by shell and not nohup
? If so then how can nohup
take any action based on weather redirection is present or not?– Piotr Dobrogost
Jan 21 '15 at 8:29
GNU nohup says that it'll redirect stdout to a file if you specify
nohup command > file
Isn't redirection in case of nohup command > file
being handled by shell and not nohup
? If so then how can nohup
take any action based on weather redirection is present or not?– Piotr Dobrogost
Jan 21 '15 at 8:29
The file
nohup.out
will be created in the case of error output, too; but if you redirect both stdout and stderr, there cannot be any output, so the file will not be created. But the &>
syntax is not POSIX-compliant; you're better off with the answer by Irshad Khan elsewhere on this page.– tripleee
Apr 20 '18 at 7:14
The file
nohup.out
will be created in the case of error output, too; but if you redirect both stdout and stderr, there cannot be any output, so the file will not be created. But the &>
syntax is not POSIX-compliant; you're better off with the answer by Irshad Khan elsewhere on this page.– tripleee
Apr 20 '18 at 7:14
add a comment |
To Append output in user defined file you can use >>
in nohup command.
nohup php your_command >> filename.out 2>&1 &
This command will append all output in your file without removing old data.
1
And if you want to overwrite the output file using POSIXsh
syntax, that's simplynohup your_command >filename.out 2>&1 &
– tripleee
Apr 20 '18 at 7:15
add a comment |
To Append output in user defined file you can use >>
in nohup command.
nohup php your_command >> filename.out 2>&1 &
This command will append all output in your file without removing old data.
1
And if you want to overwrite the output file using POSIXsh
syntax, that's simplynohup your_command >filename.out 2>&1 &
– tripleee
Apr 20 '18 at 7:15
add a comment |
To Append output in user defined file you can use >>
in nohup command.
nohup php your_command >> filename.out 2>&1 &
This command will append all output in your file without removing old data.
To Append output in user defined file you can use >>
in nohup command.
nohup php your_command >> filename.out 2>&1 &
This command will append all output in your file without removing old data.
edited Apr 20 '18 at 7:10
answered Aug 18 '17 at 15:10
Irshad KhanIrshad Khan
16114
16114
1
And if you want to overwrite the output file using POSIXsh
syntax, that's simplynohup your_command >filename.out 2>&1 &
– tripleee
Apr 20 '18 at 7:15
add a comment |
1
And if you want to overwrite the output file using POSIXsh
syntax, that's simplynohup your_command >filename.out 2>&1 &
– tripleee
Apr 20 '18 at 7:15
1
1
And if you want to overwrite the output file using POSIX
sh
syntax, that's simply nohup your_command >filename.out 2>&1 &
– tripleee
Apr 20 '18 at 7:15
And if you want to overwrite the output file using POSIX
sh
syntax, that's simply nohup your_command >filename.out 2>&1 &
– tripleee
Apr 20 '18 at 7:15
add a comment |
There are more ways than just nohup
to start a process so that it would ignore SIGHUP; for example: (written as shell functions)
nohup() {
setsid "$@"
}
nohup() {
("$@" &)
}
nohup() {
"$@" & disown
}
(setsid
, or even (setsid "$@" &)
, might be the best choice.)
All of them allow you to specify your own redirections with >
, 2>
, and &>
/>&
.
add a comment |
There are more ways than just nohup
to start a process so that it would ignore SIGHUP; for example: (written as shell functions)
nohup() {
setsid "$@"
}
nohup() {
("$@" &)
}
nohup() {
"$@" & disown
}
(setsid
, or even (setsid "$@" &)
, might be the best choice.)
All of them allow you to specify your own redirections with >
, 2>
, and &>
/>&
.
add a comment |
There are more ways than just nohup
to start a process so that it would ignore SIGHUP; for example: (written as shell functions)
nohup() {
setsid "$@"
}
nohup() {
("$@" &)
}
nohup() {
"$@" & disown
}
(setsid
, or even (setsid "$@" &)
, might be the best choice.)
All of them allow you to specify your own redirections with >
, 2>
, and &>
/>&
.
There are more ways than just nohup
to start a process so that it would ignore SIGHUP; for example: (written as shell functions)
nohup() {
setsid "$@"
}
nohup() {
("$@" &)
}
nohup() {
"$@" & disown
}
(setsid
, or even (setsid "$@" &)
, might be the best choice.)
All of them allow you to specify your own redirections with >
, 2>
, and &>
/>&
.
answered Feb 14 '13 at 15:48
grawitygrawity
241k37508563
241k37508563
add a comment |
add a comment |
Thanks for contributing an answer to Super User!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f552133%2fnohup-output-redirection-to-a-different-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown