I've got a little script here that should be pretty self explanatory but I can't figure out why the while loop doesn't handle the functions right. It should show the getinfo function again if the user presses N for no and if the user press yes it should execute the writeinterfacefile function.
What is wrong whith my loop?
#!/bin/bash
echo "Let's set up a static ip address for your site"
echo""
getinfo()
{
read -p "Enter the IP of your router: (looks like 192.168.1.1) " routerip
read -p "Enter the netmask for your network: (looks like 255.255.255 " netmask
read -p "Enter the ip address for your server: (looks like 192.168.1.22 " staticip
}
writeinterfacefile()
{
cat << EOF >> /home/ubuntu/test
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet dhcp
#Your static network configuration
iface eth0 inet static
address echo $staticip
netmask echo $netmask
gateway echo $routerip
EOF
}
clear
getinfo
echo""
echo"So your settings are"
echo "Address of your Router is " echo -n $routerip
echo "The Mask fpr the Network is " echo -n $netmask
echo "Your decided Server IP is " echo -n $istaticp
echo""
echo "Are these informations correct? (Y/n)"
while true; do
read -p "Are these informations correct? [y/N]" yn?
case $yn in
[Yy]* ) writeinterfacefile ;;
[Nn]* ) getinfo ;;
* ) echo "Pleas enter Y or n";;
esac
done
I found some mistakes in your script. Here is how I think it should be (assuming that these are the things that you want to do this script):