Learning stage of understanding script. I have to make these below change on every new system. So I created these script, unfortunately it isn't working.
I want to understand that if the user input is read and kept in a variable how can I use it again after some time. Like in this script I have asked the user for their input Is this a DNS Server
and what is the rev of the server
.
#!/bin/bash
echo -n "Is this a DNS Server [y n]?"
read command
if [ $command = n ]
then
yum -y install dnsmasq
yum -y install net-snmp net-snmp-utils
elif [ $command = n ]
then
echo $command
else
echo "DNS Package installation should be excluded"
fi
cat <<EOF>> scriptos.sh
!/bin/sh
export rev="avi"
export DNS_FLG="Y"
export DNS_FLG="N"
EOF
echo -n "what is the rev of the server"
read rev
if [ $rev = y ]
then
echo export LOC=$rev
if [ $rev = N ]
then
echo export DNS_FLG="Y"
if [ $rev = Y ]
then
echo export DNS_FLG="Y"
fi
echo "what your GW"
read GW
echo "what is your NW"
read NW
echo 192.168.0.0/16 via ${GW} > /etc/sysconfig/network-scripts/route-eth1
echo ${NW} via ${GW} >> /etc/sysconfig/network-scripts/route-eth1
/etc/init.d/network restart
This script is not working because of this bellow error.
[root@centos6 ~]# ./script
Is this a DNS Server [y n]?y
DNS Package installation should be excluded
what is the rev of the servery
./script: line 57: syntax error: unexpected end of file
n
inside quotes. (The$command
can also be quoted in case there might be a whitespace).