문제

I'm pretty much a novice in speaking Ruby. I'm trying to write a template (.erb) for Puppet. My goal is to based on this variable:

$c_repo = 'repo1,repo1-condb,repo2,....'

to write a template, which in turn shall create a cron-job file like this:

43 2 * * * root /etc/zmfs/zmfs-check.sh repo1 >> /var/log/zmfs.log 2>&1
45 2 * * * root /etc/zmfs/zmfs-check.sh repo1-condb >> /var/log/zmfs.log 2>&1
....

I can create a fairly simple one with single value though:

$c_repo = 'repo1'
43 2 * * * root /etc/zmfs/zmfs-check.sh <%= c_repo %> >> /var/log/zmfs.log 2>&1

but just can't figure out how to create the loop for the list. Any help greatly appreciated. Cheers!!

도움이 되었습니까?

해결책

This should work:

<% c_repo.split(',').each_with_index do |repo, i| -%>
<%= (i*2)%60 %> 2 * * * root /etc/zmfs/zmfs-check.sh <%= repo %> /var/log/zmfs.log 2>&1
<% end -%>

Output:

0 2 * * * root /etc/zmfs/zmfs-check.sh repo1 /var/log/zmfs.log 2>&1
2 2 * * * root /etc/zmfs/zmfs-check.sh repo1-condb /var/log/zmfs.log 2>&1
4 2 * * * root /etc/zmfs/zmfs-check.sh repo2 /var/log/zmfs.log 2>&1
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top