How can I run a sudo command using nohup? I want to execute a sudo command and then terminate the ssh session but without interrupting or stopping the process.
I tried this but it doesn't work
sudo nohup . test.sh
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
nohup sudo <command> &
The second problem is the way of execution:
. script will not work with
. is a shell internal command and
nohup only takes executables. This should also be visible in
nohup.out as error message.
nohup sudo /bin/bash script.sh &
(or whichever shell you run) or make the script an executable.
Its not sudo command failure, but
. failure because it is internal shell command. Those can be valid:
sudo nohup /bin/bash test.sh
nohup sudo /bin/bash test.sh
The difference is the owner of nohup.out
sudo /bin/bash test.sh & disown %1
(sudo /bin/bash test.sh &)
Use > logfile 2>&1 if you need log in two latter cases. And depending on script nature you may not have to specify
/bin/bash at all.