簡體   English   中英

我們如何通過使用p提供程序來應用Shell命令?

[英]How can we apply shell commands by using puppet providers?

我有我的自定義人偶提供者,其屬性確保如下。

....
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命令。

提前致謝。

在Ruby中,有一些方法可以執行Shell命令。 但是,您實際想要做的就是做到這一點(未經測試):

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM