3 # Parse the object names out of Nagios' xdata/xodtemplate.h, and
4 # convert them to their definition format.
6 # Operates on whatever file you give it, like the other utilities.
10 EXIT_INPUT_FILE_DOESNT_EXIST
=2
11 EXIT_OUTPUT_FILE_EXISTS
=3
14 echo "Usage: $0 <input_file> <output_file>"
22 if [ ! -f "$INFILE" ]; then
23 echo "Error: input file $INFILE doesn't exist."
24 exit $EXIT_INPUT_FILE_DOESNT_EXIST
27 if [ -f "$OUTFILE" ]; then
28 echo "Error: output file $OUTFILE already exists."
29 exit $EXIT_OUTPUT_FILE_EXISTS
32 # Common options. Color screws up the output.
33 GREP
="grep --extended-regexp --color=never"
35 # Grep grabs all of the "#define XODTEMPLATE_..." lines, except for
36 # XODTEMPLATE_NONE, which ain't real.
38 # Sed removes the "XODTEMPLATE_" prefixes, then tr lowercases everything.
40 # Oh and we sort everything, add "define ", and surround each line with
41 # quotes, because we can get away with it here.
43 $GREP --only-matching '[[:space:]]XODTEMPLATE_[[:alnum:]_]+' "$INFILE" \
44 | $GREP -v 'XODTEMPLATE_NONE' \
45 | sed 's/ XODTEMPLATE_//g' \
46 | tr '[A-Z]' '[a-z]' \
48 | sed -e 's/^/\"define /g' -e 's/$/\"/g' >> "$OUTFILE"