我们如何通过使用木偶提供程序来应用shell命令?

时间:2015-03-19 04:17:04

标签: ruby linux shell puppet

我的定制木偶提供商的属性如下所示。

....
def create 
     /* echo 'show system uptime' >> /home/Vinoth/config_vino.txt */
end

def destroy
     FileUtils.rm_rf '/home/Vinoth/config_vino.txt'
end

def exists?
     File.file? 'config_vino.txt'
end

在清单ensure = 'present'中。因此,当文件config_vino.txt不存在时,我想使用shell命令echo创建它。谁能建议如何实现这一目标?希望我的问题很清楚,如果没有,请回来。

我的目标是使用木偶提供程序执行shell命令。

提前致谢。

1 个答案:

答案 0 :(得分:1)

在Ruby中,有一些方法可以执行shell命令。但是,你真正想做的是相当于这个(未经测试的):

def create
  uptime = `your uptime command`
  Puppet::FileSystem.open(filename, nil, 'w') do |file|
    file.write("#{uptime}\n")
  end
end
相关问题