LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-17-2005, 03:21 AM   #1
azx
LQ Newbie
 
Registered: Aug 2005
Posts: 3

Rep: Reputation: 0
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
 
Old 08-17-2005, 05:27 AM   #2
jonaskoelker
Senior Member
 
Registered: Jul 2004
Location: Denmark
Distribution: Ubuntu, Debian
Posts: 1,524

Rep: Reputation: 47
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])
Also, google for `Advanced Bash Scripting Guide' (I think it's on tldp.org).

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
 
Old 08-17-2005, 05:58 AM   #3
azx
LQ Newbie
 
Registered: Aug 2005
Posts: 3

Original Poster
Rep: Reputation: 0
Thank you. Will look into the advanced guide.
 
Old 08-17-2005, 07:01 AM   #4
jonaskoelker
Senior Member
 
Registered: Jul 2004
Location: Denmark
Distribution: Ubuntu, Debian
Posts: 1,524

Rep: Reputation: 47
you're welcome.
 
Old 08-17-2005, 07:50 AM   #5
Ynot Irucrem
Member
 
Registered: Apr 2005
Location: Perth, Western Australia
Distribution: Debian
Posts: 233

Rep: Reputation: 30
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.
 
Old 08-18-2005, 02:27 AM   #6
azx
LQ Newbie
 
Registered: Aug 2005
Posts: 3

Original Poster
Rep: Reputation: 0
hehe, you're right.
Its fixed now, thank you.

Quote:
no offense, but in professional applications, bad grammar doesn't go over well.
Thank you for the "professional" statement there
 
Old 08-18-2005, 11:36 AM   #7
Ynot Irucrem
Member
 
Registered: Apr 2005
Location: Perth, Western Australia
Distribution: Debian
Posts: 233

Rep: Reputation: 30
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...)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash Script zaicheke Programming 3 11-07-2004 07:32 PM
bash script how to? Lleb_KCir Programming 11 05-21-2004 08:03 PM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 01:20 AM
bash script - incrementing a filename in a script tslinux Programming 10 08-06-2003 12:58 AM
bash script prob: how can i tell the script that a 'dd' has finished? Frustin Linux - General 2 04-02-2003 06:34 AM


All times are GMT -5. The time now is 11:52 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration