Everything I have tried from other examples I have found on SO don't seem to work. I am trying to run my application using nohup but append the output of the application to a file.
I have tried some of the following. None of which seem to work.
nohup dotnet application.dll &> out.log &
nohup dotnet application.dll > out.log 2>&1 &
nohup dotnet application.dll > /opt/out.log &
I always receive something like
-bash: out.log: Permission denied
I have tried running the application using sudo but it still doesn't seem to work.
nohup dotnet application.dll &
Works fine, but it directs the output to some other directory like /home/ubuntu/nohup.out
What am I doing wrong?
Edit: I didn't read your link at first; you may have a different version of nohup, although this section suggests that you can still use normal redirection: nohup.out The output file of the nohup execution if standard output is a terminal and if the current directory is writable.
Once you run the command with nohup, you should get an output such as: By default, nohup runs a process in the foreground while redirecting the output to nohup.out file. The file is located in the current working directory unless the user does not have write permissions in that directory.
To run a command, such as a ping, with nohup, use the command: Once you run the command with nohup, you should get an output such as: By default, nohup runs a process in the foreground while redirecting the output to nohup.out file.
Your problem lies in the file permissions (or a read-only filesystem). Prepending sudo to your command can't fix this, because only nohup dotnet application.dll is executed as root by sudo, the output redirection is done by bash with your normal user privileges. You can work around this by calling a separate shell with root privileges:
nohup dotnet application.dll > out.log 2>&1 &
is the correct form.
> out.log
redirects STDOUT to the file out.log
.
2>&1
redirects fd2 (STDERR) to fd1 (STDOUT), which is already redirected to the file out.log
.
Your problem lies in the file permissions (or a read-only filesystem). Prepending sudo
to your command can't fix this, because only nohup dotnet application.dll
is executed as root by sudo
, the output redirection is done by bash with your normal user privileges. You can work around this by calling a separate shell with root privileges:
sudo sh -c 'nohup dotnet application.dll > out.log 2>&1 &'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With