我正在尝试打印受Chef中的cron作业配方影响的所有服务器的列表,我想在特定服务器的每个cron作业旁边打印cron时间值。
我已经使用过这样的脚本:
for i in $(ls cookbooks/cookbook_name/recipes);
do knife search node "recipes:*${i%.*}" -i;
done
我想从这样的表达式中提取crontab
时间:
% frequent zfs snapshot
cron_d 'zfs-auto-snapshot-frequently' do
minute '*/15'
path PATH
command '/opt/zfs-auto-snapshot.sh frequent 6'
end
% Hourly
cron_d 'zfs-auto-snapshot-hourly' do
minute '59'
path PATH
command '/opt/zfs-auto-snapshot.sh hourly 4'
end
% Daily
cron_d 'zfs-auto-snapshot-daily' do
minute '59'
hour '23'
path PATH
command '/opt/zfs-auto-snapshot.sh daily 3'
end
% Weekly
cron_d 'zfs-auto-snapshot-weekly' do
minute '0'
hour '0'
weekday '1'
path PATH
command '/opt/zfs-auto-snapshot.sh weekly 1'
end
% Monthly
cron_d 'zfs-auto-snapshot-monthly' do
minute '0'
hour '0'
day '1'
path PATH
command '/opt/zfs-auto-snapshot.sh monthly 1'
end
admindb.xyz.com *** 3 *
server.xyz.com *** 3 *
office.xyz.com * 2 ***
collector01.xyz.com * 3 * 4 *
答案 0 :(得分:1)
要对代码做出大量假设并编写一些糟糕的正则表达式,这实际上是不可能的。 Chef是代码,对任何代码进行静态分析都很困难,而使用Ruby则介于激怒和“ lolno”之间。最好的选择是不要看Chef,而是通过SSH直接查询每台计算机。