This is fairly straightforward in any scripting language that has a YAML library. For example, here's how you might do it in Ruby:
#!/usr/bin/env ruby
require "yaml"
def check_file(filename)
YAML.parse_file(filename)
puts "OK"
0
rescue Psych::SyntaxError => ex
puts "Error#{ex.message[/: .+/]}"
1
end
exit_code = 0
max_filename_length = ARGV.max_by(&:size).size
ARGV.each do |filename|
printf "%-*s ", max_filename_length, filename
exit_code |= check_file(filename)
end
exit exit_code
Usage:
$ ruby check_yaml.rb *.yml
config-1.yml OK
config-2.yml OK
invalid.yml Error: did not find expected key while parsing a block mapping at line 2 column 3
xyzzy.yml OK
$ echo $EXIT_CODE
1