让sudo和nohup一起工作 [英] Getting sudo and nohup to work together

查看:2847
本文介绍了让sudo和nohup一起工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Linux新手在这里.

Linux newbie here.

我有一个perl脚本,需要两个命令行输入.我试图在后台运行它,但这就是我得到的:

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 sudo ./ascii_loader_script.pl 20070502 ctm_20070502.csv &
[2] 19603
[~user]$ nohup: appending output to `nohup.out'

在系统返回"nohup:将输出附加到`nohup.out'"之后,将不会出现新的提示.然后,只要我键入其他命令,shell就会告诉我该进程已停止:

after the system returns "nohup: appending output to `nohup.out'", no new prompt will appear. Then as long as I type in some other command, the shell will tell me that the process is stopped:

[~user]$ nohup sudo ./ascii_loader_script.pl 20070502 ctm_20070502.csv &
[2] 19603
[~user]$ nohup: appending output to `nohup.out'
ls
ascii_loader_script.pl  format_wrds_trd.txt  nohup.out  norm_wrds_trd.cfg
[2]+  Stopped                 nohup sudo ./ascii_loader_script.pl 20070502 ctm_20070502.csv

我已经看过这篇文章,并在执行命令之前尝试执行"sudo date".还是一样. http://www.sudo.ws/pipermail/sudo-users/2003-July/001648.html

I've looked at this post and tried to do "sudo date" before executing the command. Still got the same thing. http://www.sudo.ws/pipermail/sudo-users/2003-July/001648.html

推荐答案

这里的问题,恕我直言,不是nohup,而是后台处理sudo.

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

您将进程置于后台(命令末尾为&),但是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.

尝试以下方法之一:

1)从命令末尾删除&符号,回复密码提示,后记将其置于后台(通过键入CTRL-Z-这将停止该过程并发出bg命令将其发送至后台)

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)通过添加以下行来更改/etc/sudoers以不要求用户输入密码: myusername ALL =(全部)NOPASSWD:全部

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

如果除了密码回复之外,您的应用程序还等待其他输入,那么您可以将输入通过管道传递给以下命令: $ cat response.txt | sudo mycommand.php

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

这篇关于让sudo和nohup一起工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆