I'm creating a script to more easily allow my organization to add workstations to our Nagios monitoring system.
Each time the script runs, I'd like to be able to input the hostname, alias,and address, ( as variables input by user ) and have those variables called WITHIN the sed command so as to "create" a new host much faster then typing it all out.
I'm attempting to add the entire string AFTER sed finds " address of the host }"
which i assumed was /a ( append after it finds said string ) Still, using double quotes hasn't allowed the variables to be called.
#!bin/bash
# Prompt for hostname, alias, and IP address of new host
# take user input has variable to be used in sed
# Takes user input for hostname
echo host_name :
read var_hostname
# Takes user input for alias
echo alias :
read var_alias
# Takes user input for ip address
echo address :
read var_address
# searches for the top-most instance "address of the host" within the windows.cfg file
# after said instance is found, appends the new string below, which calls for the variables received
# previously by user
sed -i -e " address of the host } /a
define host{
use windows-server ; Inherit default values from a template
host_name $var_hostname ; The name we are giving to this host
alias $var_alias ; A longer name associated with the host
address $var_address ; IP address of the host
}"
windows.cfg
I want the string "define host{}" to be written to the file with the variables the user put in. Instead