onlyif不在exec资源中工作

时间:2016-08-19 12:48:01

标签: puppet

exec { 'add text to file':
  cwd     => '/usrdata/apps/java',
  command => 'command which writes a line in file',       
  onlyif  => "grep -c -w line-in-file /path/to/file"
}

即使grep命令返回1,exec资源也会被执行。我哪里错了?

1 个答案:

答案 0 :(得分:0)

exec { 'add text to file':
  cwd     => '/usrdata/apps/java',
  command => "grep -q -F -v 'text to check if present or not' /usrdata/apps/java || echo 'text to add' >> location_of_file.txt",
}

如果文件中已存在文本,则不会添加文本。

相关问题