检查文件是否存在,存在则删除
Check if file exists and delete it if it exists
我的问题是:我想检查/tmp
文件夹中是否存在文件,并在重新开始下载前删除它。
这是我的代码(木偶):
exec { 'Download mediawiki to temp':
cwd => '/tmp',
command => '/usr/bin/wget https://releases.wikimedia.org/mediawiki/1.27/mediawiki-1.27.1.tar.gz',
}
您可能想要这样做...
# local vars for readability
$theurl = 'https://releases.wikimedia.org/mediawiki/1.27'
$tarball = 'mediawiki-1.27.1.tar.gz'
$wget_command = "/usr/bin/wget $theurl/$tarball"
$rm_command = "/bin/rm -f /tmp/$tarball"
exec { 'Delete mediawiki from temp':
cwd => '/tmp',
command => $rm_command,
}->
exec { 'Download mediawiki to temp':
cwd => '/tmp',
command => $wget_command,
creates => "/tmp/$tarball",
}
见https://docs.puppet.com/puppet/latest/reference/types/exec.html and https://docs.puppet.com/puppet/latest/reference/lang_relationships.html
我的问题是:我想检查/tmp
文件夹中是否存在文件,并在重新开始下载前删除它。
这是我的代码(木偶):
exec { 'Download mediawiki to temp':
cwd => '/tmp',
command => '/usr/bin/wget https://releases.wikimedia.org/mediawiki/1.27/mediawiki-1.27.1.tar.gz',
}
您可能想要这样做...
# local vars for readability
$theurl = 'https://releases.wikimedia.org/mediawiki/1.27'
$tarball = 'mediawiki-1.27.1.tar.gz'
$wget_command = "/usr/bin/wget $theurl/$tarball"
$rm_command = "/bin/rm -f /tmp/$tarball"
exec { 'Delete mediawiki from temp':
cwd => '/tmp',
command => $rm_command,
}->
exec { 'Download mediawiki to temp':
cwd => '/tmp',
command => $wget_command,
creates => "/tmp/$tarball",
}
见https://docs.puppet.com/puppet/latest/reference/types/exec.html and https://docs.puppet.com/puppet/latest/reference/lang_relationships.html