Scene
When executing the nohup command, there are often the following errors that do not have write permissions.
nohup:ignoring input and appending output to ' nohup.out '
nohup:failed to Run command '/etc/nginx_check.sh ': Permission denied
Linux redirection:
0, 1, and 2 represent standard input, standard output, and standard error message output, which can be used to specify the standard input or output that needs to be redirected.
when used in general, The default is standard output, both 1. when we need special use, we can use other labels.
For example, output a program's error message to the log file:./program 2>log. The standard output is still on the screen, but the error message is output to the log file.
In addition, redirects can be implemented between 0,1,2. 2>&1: redirect error messages to standard output.
Linux also has a special file/dev/null, it is like a bottomless pit, all the information redirected to it will disappear into a trace .
This is useful when we do not need to echo all of the program's information, so we can redirect the output to/dev/null.
If you want both the normal output and the error message to be displayed, redirect both the standard output and the standard error to/dev/null, for example:
# ls 1>/dev/null 2>/dev/null
Another approach is to redirect errors to standard output and then redirect to/dev/null, for example:
# ls >/dev/null 2>&1
Note: The order here cannot be changed, otherwise the desired effect is not achieved, when the standard output is redirected to/dev/null, and then the standard error is redirected to standard output.
Because standard output has been redirected to/dev/null, standard errors are redirected to/dev/null, so everything is quiet.
About Nohup
When using the Nohup command, it is often not possible to use nohup because the path of the output nohup.out does not have write permission.
This is a way to use Linux redirection, redirect nohup.out to a path with write permission, or throw it directly into/dev/null.
Nohup./program >/dev/null 2>/dev/null &
Or
Nohup./program >/dev/null 2>&1 &
Using Linux redirection to resolve nohup.out no write permission issues