All pastes #479516 Raw Edit

Someone

public text v1 · immutable
·published 2007-05-09 19:55 UTC
rendered paste body
#!/bin/bash

#This is the path I took to write a script that takes a file and puts each line into
#an array.  This allows me to organize data in a file, seperated by spaces, and
#output that data into any format that I would want.
#This example is for writing a very quick nagios config.

#file=/home/steven/test/file.txt
#cat $file | while read line
#do
#echo $line
#done

#file=/home/steven/nagios/hosts
#cat $file | while read line
#do
#array=($line)
#echo -e "${array[0]}\t${array[1]}"
#####echo -e "poop\t$line"
#done

#Here is an example of output
#define host {
#use generic-host
#        host_name               10.0.0.4
#        alias                   poop
#        address                 POOP
#        check_command           check-host-alive
#        max_check_attempts      20
#        notification_interval   60
#        notification_period     24x7
#        notification_options    d,u,r
#        }

file=/home/steven/nagios/hosts
cat $file | while read line
do
array=($line)
echo -e "define host {"
echo -e "use generic-host"
echo -e "\thost_name\t\t${array[0]}"
echo -e "\talias\t\t\t${array[1]}"
echo -e "\taddress\t\t\t${array[2]}"
echo -e "\tcheck_command\t\tcheck-host-alive"
echo -e "\tmax_check_attempts\t20"
echo -e "\tnotification_interval\t60"
echo -e "\tnotification_period\t24x7"
echo -e "\tnotification_options\td,u,r"
echo -e "\t}"
echo -e "\n"
done