使用Ruby
我希望将cron
中出现的任何范围扩展为范围ex:
0,5,7,30-35 1,3-8,20 * * * /script.sh
扩展:
0,5,7,31,32,33,34,35 1,3,4,5,6,7,8,20 * * * /script.sh
感谢任何帮助
答案 0 :(得分:4)
假设0,5,7,30-35 1,3-8,20 * * * /script.sh
是一个字符串,一个简单的gsub
就可以了:
str = "0,5,7,30-35 1,3-8,20 * * * /script.sh"
str.gsub(/(\d+)-(\d+)/) { ($1..$2).to_a.join(',') }
#=> "0,5,7,30,31,32,33,34,35 1,3,4,5,6,7,8,20 * * * /script.sh"