简体   繁体   English

人偶执行命令问题

[英]puppet exec command issue

Below is my puppet code ,It is killing the process in agent but showing the error code 下面是我的木偶代码,它正在杀死代理中的进程但显示错误代码

exec { "restart_process":
    command => "ps -ef | grep nrpe | grep -v pts/1 | /bin/awk '{print $2}' | xargs kill -9",
    path => ['/usr/bin', '/sbin', '/bin', '/usr/sbin'],
    subscribe => File["/root/Backup/deploy"],
    refreshonly => true,
}

Error code: 错误代码:

Info: Computing checksum on file /root/Backup/deploy/nrpe.sh
Info: /Stage[main]/Myfile/File[/root/Backup/deploy/nrpe.sh]: Filebucketed /root/Backup/deploy/nrpe.sh to puppet with sum   136c6013774f5dfb84943718a70b36e0
Notice: /Stage[main]/Myfile/File[/root/Backup/deploy/nrpe.sh]/content: content 
changed '{md5}136c6013774f5dfb84943718a70b36e0' to '{md5}c4fc9099405a108923ad18f7e2db13c8'
Info: /root/Backup/deploy: Scheduling refresh of Exec[restart_process]
Error: /Stage[main]/Myfile/Exec[restart_process]: Failed to call refresh: ps -ef | grep nrpe | grep -v pts/1 | /bin/awk '{print }' | xargs kill -9 returned  instead of one of [0]
Error: /Stage[main]/Myfile/Exec[restart_process]: ps -ef | grep nrpe | grep -v pts/1 | /bin/awk '{print }' | xargs kill -9 returned  instead of one of [0]
Notice: Finished catalog run in 1.56 seconds

Can any body help me 有谁能够帮助我

@maxd is right that you need to escape the $ in the command when you specify it to Puppet. @maxd是正确的,当您将其指定给Puppet时,您需要在命令中转义$ This is because Puppet performs its own variable interpolation on quotation-mark-quoted strings, and this will replace the $2 with the relevant replacement string -- probably an empty string -- before your command even reaches the catalog, and long before any attempt is made to run it. 这是因为Puppet对用引号引起来的字符串执行自己的变量插值,这将在命令甚至到达目录之前,并且很长时间之前,用相关的替换字符串(可能是空字符串)替换$2 。进行运行。

I don't think that's your fundamental problem, however. 但是,我认为这不是您的根本问题。 Your command is a shell pipeline, but the default Exec provider for your system is almost certainly posix , and that provider will not do what you want with the command string you provided. 您的命令是Shell管道,但是系统的默认Exec提供程序几乎可以肯定是posix ,并且该提供程序不会使用您提供的命令字符串来执行您想要的操作。 You probably want to add 您可能要添加

provider => 'shell'

to your resource, to have Puppet use the shell to execute it instead of trying to execute it directly as a (single) command. 对于您的资源,要让Puppet使用外壳执行它,而不是尝试直接(单个)命令来执行它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM