Getting sudo and nohup to work together

后端 未结 9 1633
滥情空心
滥情空心 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:20

    The solution is to use the -b flag for sudo to run the command in the background:

    $ sudo -b ./ascii_loader_script.pl 20070502 ctm_20070502.csv
    

    You should only use nohup if you want the program to continue even after you close your current terminal session

    0 讨论(0)
  • 2021-02-02 07:23

    The problem here, imho, is not nohup, but background processing sudo.

    You are putting the process in background (& at end of command) but probably sudo needs password authentication, and that is why the process stops.

    Try one of these:

    1) remove the ampersand from end of command, reply to passord prompt and afterwords put it in background (by typing CTRL-Z - which stops the process and issuing the bg command to send it to background)

    2) Change the /etc/sudoers to not ask for users password by including the line: myusername ALL=(ALL) NOPASSWD: ALL

    If besides the password reply your application waits for other input, then you can pipe the input to the command like this: $ cat responses.txt|sudo mycommand.php

    hth

    0 讨论(0)
  • 2021-02-02 07:23

    You can Try

    sudo su
    

    and then

    nohup ./ascii_loader_script.pl 20070502 ctm_20070502.csv &
    

    instead of

    nohup sudo ./ascii_loader_script.pl 20070502 ctm_20070502.csv &
    
    0 讨论(0)
提交回复
热议问题