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
资源也会被执行。我哪里错了?
答案 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",
}
如果文件中已存在文本,则不会添加文本。