Getting sudo and nohup to work together

后端 未结 9 1849
滥情空心
滥情空心 2021-02-02 06:39

Linux newbie here.

I have a perl script which takes two command line inputs. I tried to run it in the background but this is what I got:

[~user]$ nohup s         


        
9条回答
  •  天命终不由人
    2021-02-02 07:16

    First of all, you should switch sudo and nohup. And then:

    if sudo echo Starting ...
    then
        sudo nohup  &
    fi
    

    The echo Starting ... can be replaced by any command that does not do much. I only use it as dummy command for the sudo.

    By this the sudo in the if-condition triggers the password-check. If it is ok then the sudo session is logged in and the second call will succeed, otherwise the if will fail and not execute the actual command.

提交回复
热议问题