using ruby modify file content.
config的內容中找到"owner_include"區段將"profile normal"替換成"profile privileged"。
- <--
- Dir.chdir("/usr/local/sympa/expl")
- Dir.glob("*-*").each do |x|
- if File::directory?(x)
- config_file = File.join(x, 'config')
- if File.exist?(config_file)
- puts config_file
- flag = false
- File.open(config_file, 'r+') do |f|
- out = ""
- f.each do |line|
- if line =~ /owner_include/
- flag = true
- elsif line =~ /^$/
- flag = false
- elsif flag == true
- if line =~ /profile normal/
- line = "profile privileged\n"
- end
- end
- out << line
- end
- #write to file
- f.pos = 0 #from line 1
- f.print out #write
- f.truncate(f.pos) #truncate after current position
- end
- end
- end
- end
沒有留言:
張貼留言