bash script
Hi all
I'm writing my first bash script ever. My boss wanted me to automate a install CD for our costumers. we send out boxes, and they boot off a mkcdrec made image. The script ask them for their IP, mask and gateway. When they enter their info I want the script to check that they have typed in a valid IP, mask and gateway. I have read up on regex, but its way over my head. Im very interested in learning this, so if anyone could point me in the right direction it would be great. But for now, can anyone try to explain this to me, with some examples and plain English :) I know this script prolly could be written in two lines. But I need to do it like this so I can see what happens step by step. And keep in mind, I'm new to this :) my script #### #!/bin/bash echo "Please enter your IP adress" echo -n "Enter ip:" read ip echo echo "Please enter subnetmask" echo -n "Enter subnetmask:" read subnetmask echo echo "Please enter gateway" echo -n "Enter gateway:" read gateway echo echo "Please verify your settings!" echo echo IP=$ip echo Subnet=$subnetmask echo Gateway=$gateway echo echo -n "is the above settings correct? yes/no:" read answer if [ "$answer" = "yes" ];then echo "setting new configuration now" sed "s/new-ip/$ip/" rc.inet1.conf-template > rc.inet1.conf.tmp1 sed "s/new-subnet/$subnetmask/" rc.inet1.conf.tmp1 > rc.inet1.conf.tmp2 sed "s/new-gateway/$gateway/" rc.inet1.conf.tmp2 > rc.inet1.conf.tmp mv rc.inet1.conf.tmp rc.inet1.conf rm rc.inet1.conf.tmp1 ; rm rc.inet1.conf.tmp2 exit 0 else echo "restarting configuration" /root/ip.sh exit 0 fi |
you may find the following regexp outline useful:
Code:
(0|[1-9][0-9]?|1[0-9][0-9]|2[0-4][0-9]|25[0-5]) When posting code (or textual input/output; or anything that would do well to be in a fixed-width font), put it in code tags ("[ c o d e ] your code goes here [ / c o d e ]" -- remove all spaces between the brackets). Best wishes --Jonas |
Thank you. Will look into the advanced guide.
|
you're welcome.
|
Yeah, the Advanced Bash Scripting Guide is great for getting started with bash.
Also, you should probably change "is the above settings correct? yes/no:" to "are the above settings correct? yes/no:". no offense, but in professional applications, bad grammar doesn't go over well. |
hehe, you're right.
Its fixed now, thank you. Quote:
|
No problem :)
Haha lol... I just heard "Keep children away from Windows" on the TV. Turns out it's an ad for keeping children safe from window blinds (hmm... never heard of a kid being killed by some blinds...) |
All times are GMT -5. The time now is 04:21 PM. |