Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
|
06-21-2007, 10:18 AM
|
#16
|
Senior Member
Registered: Aug 2003
Distribution: Debian Sid 32/64-bit, F10 32/64-bit
Posts: 1,070
Original Poster
Rep:
|
I was referring to the part below of your reply (or were you explaining how the script works )
Quote:
then you just need to replace the CIDR notation with the conventional netmask.
|
|
|
|
06-21-2007, 11:46 AM
|
#17
|
Moderator
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417
|
yeah that's what the 2nd line of the two does.
|
|
|
06-23-2007, 12:59 AM
|
#18
|
Senior Member
Registered: Aug 2003
Distribution: Debian Sid 32/64-bit, F10 32/64-bit
Posts: 1,070
Original Poster
Rep:
|
When I run the script I get the following error :
Code:
./test: line 10: export: `-m': not a valid identifier
./test: line 10: export: `option:': not a valid identifier
line 10 being the line in my script with export and ipcalc. My debian ipcalc has this as options
Code:
Usage: ipcalc [options] <ADDRESS>[[/]<NETMASK>] [NETMASK]
ipcalc takes an IP address and netmask and calculates the resulting broadcast,
network, Cisco wildcard mask, and host range. By giving a second netmask, you
can design sub- and supernetworks. It is also intended to be a teaching tool
and presents the results as easy-to-understand binary values.
-n --nocolor Don't display ANSI color codes.
-b --nobinary Suppress the bitwise output.
-c --class Just print bit-count-mask of given address.
-h --html Display results as HTML (not finished in this version).
-v --version Print Version.
-s --split n1 n2 n3
Split into networks of size n1, n2, n3.
-r --range Deaggregate address range.
--help Longer help text.
It returns info like this:
Code:
[jongi:~#] ipcalc 216.104.192.0/21
Address: 216.104.192.0 11011000.01101000.11000 000.00000000
Netmask: 255.255.248.0 = 21 11111111.11111111.11111 000.00000000
Wildcard: 0.0.7.255 00000000.00000000.00000 111.11111111
=>
Network: 216.104.192.0/21 11011000.01101000.11000 000.00000000
HostMin: 216.104.192.1 11011000.01101000.11000 000.00000001
HostMax: 216.104.199.254 11011000.01101000.11000 111.11111110
Broadcast: 216.104.199.255 11011000.01101000.11000 111.11111111
Hosts/Net: 2046 Class C
EDIT: The Debian version installed is 0.41-1
Last edited by Jongi; 06-23-2007 at 01:44 AM.
|
|
|
06-23-2007, 01:58 AM
|
#19
|
Moderator
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417
|
[chris@kermit ~]$ ipcalc
ipcalc: ip address expected
Usage: ipcalc [OPTION...]
-b, --broadcast Display calculated broadcast address
-h, --hostname Show hostname determined via DNS
-m, --netmask Display default netmask for IP (class A, B, or C)
-n, --network Display network address
-p, --prefix Display network prefix
-s, --silent Don't ever display error messages
Help options:
-?, --help Show this help message
--usage Display brief usage message
this is under fedora 7, so i assume you could upgrade yours, i doubt the fedora version isn't anythign but the newest.
|
|
|
06-23-2007, 02:31 AM
|
#20
|
Senior Member
Registered: Aug 2003
Distribution: Debian Sid 32/64-bit, F10 32/64-bit
Posts: 1,070
Original Poster
Rep:
|
I'll be installing FC7 in anycase today. If I can't get a debian version that handles the -m option I will just continue the script under FC.
Chris, can you print what the output of -m looks like?
Last edited by Jongi; 06-23-2007 at 02:36 AM.
|
|
|
06-23-2007, 06:05 AM
|
#21
|
Moderator
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417
|
just "NETMASK=255.255.255.0" etc... i.e. *exactly* the right output to be used in a bash script to define a variable called NETMASK
|
|
|
06-23-2007, 03:22 PM
|
#22
|
Senior Member
Registered: Aug 2003
Distribution: Debian Sid 32/64-bit, F10 32/64-bit
Posts: 1,070
Original Poster
Rep:
|
So I installed FC7. But for various reasons I decide to finish this off in Debian. So I mounted the FC7 install in Debian and copied /bin/ipcalc (FC7) to /bin in Debian. I then ran the script. What I found interesting is that it would in places, insert the system environment variables. As they would appear if you ran env but with export in front of each variable. The script is exactly as you have it here. I will run it in due course in FC to see whether the same happens.
It was not a job to edit it manually, though either it missed one entry or I deleted one by mistake. I am going to go with the latter.
|
|
|
06-24-2007, 09:45 AM
|
#23
|
Senior Member
Registered: Aug 2003
Distribution: Debian Sid 32/64-bit, F10 32/64-bit
Posts: 1,070
Original Poster
Rep:
|
Chris - Although I still have not solved the minor problem detailed above, I want to give you my heartfelt appreciation for all the effort and help you have put in here. It has helped me enormously.
I will take some time to actually try and work out what everything does and I might come back with some questions. Again, thanks immensely.
|
|
|
06-24-2007, 11:49 AM
|
#24
|
Moderator
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417
|
no problem.
|
|
|
07-06-2007, 05:19 AM
|
#25
|
Senior Member
Registered: Aug 2003
Distribution: Debian Sid 32/64-bit, F10 32/64-bit
Posts: 1,070
Original Poster
Rep:
|
Chris - The problem persists in FC7 ie, that variables that are output when I run export from the command line appear in the output file (with export and a space ahead of them). For example, export HOME=/home/jongi appears in the file.
Below is my interpretation of the two lines:
Code:
export $(ipcalc -m $(echo $route | sed -e 's/^.*net\ \([0-9\.\/]*\).*$/\1/'))
echo $route | sed -e "s/\/[0-9]*/ netmask $NETMASK/"
I assume the first line sets up the variable NETMASK.
Code:
echo $route | sed -e 's/^.*net\ \([0-9\.\/]*\).*$/\1/'
each line of newroutes.txt is echoed and that output is processed by sed. Now how the notation for sed is translated is a bit hard for me.
Code:
^.*net\ \([0-9\.\/]*\).*$
This is what sed searches for in the echo output.
and replaces it with
How to interpret it is confusing me. My guess though (based on what it is I am trying to achieve here) is that it outputs something like 216.104.192.0/21. And this is then used by ipcalc to run ipcalc -m 216.104.192.0/21. This returns NETMASK=255.255.248.0 which is then set as the variable NETMASK by export.
Code:
echo $route | sed -e "s/\/[0-9]*/ netmask $NETMASK/"
The second line takes the same line that has been processed above and replaces /21 with netmask 255.255.248.0. Does it as follows:
Code:
echo $route | sed -e "s/\/[0-9]*/ netmask $NETMASK/"
Sed again processes the output of echo. Sed searches for
a number starting with 0-9, the start means it is more than 1 digit (?) and preceded by / ie a number like /21
Code:
/ netmask $NETMASK/"
replaces /21 with netmask 255.255.248.0.
Last edited by Jongi; 07-06-2007 at 05:22 AM.
|
|
|
07-06-2007, 02:56 PM
|
#26
|
Senior Member
Registered: Aug 2003
Distribution: Debian Sid 32/64-bit, F10 32/64-bit
Posts: 1,070
Original Poster
Rep:
|
Given my limited knowledge I think this is what is causing the problem
Code:
[root:~#] cat newroutes.txt | grep host | more
route add -host 155.237.171.98/32 ppp1
route add -host 163.195.16.25/32 ppp1
route add -host 163.195.16.155/32 ppp1
route add -host 164.147.241.195/32 ppp1
route add -host 196.6.240.2/32 ppp1
route add -host 196.14.176.115/32 ppp1
route add -host 196.23.48.244/32 ppp1
route add -host 196.23.48.245/32 ppp1
route add -host 196.34.16.71/32 ppp1
There also happen to be the same number of instances where a problem occurs. My suspicions lie with this part of the script
Code:
^.*net\ \([0-9\.\/]*\).*$
|
|
|
07-06-2007, 03:01 PM
|
#27
|
Senior Member
Registered: Aug 2003
Distribution: Debian Sid 32/64-bit, F10 32/64-bit
Posts: 1,070
Original Poster
Rep:
|
I pipe the output of the script in post 13 to a file called netroutes.txt
Code:
[root:~#] cat netroutes.txt | grep host
export HOSTNAME="localhost.localdomain"
export SESSION_MANAGER="local/localhost.localdomain:/tmp/.ICE-unix/23350"
route add -host 155.237.171.98 netmask 255.255.0.0 ppp1
export HOSTNAME="localhost.localdomain"
export SESSION_MANAGER="local/localhost.localdomain:/tmp/.ICE-unix/23350"
route add -host 163.195.16.25 netmask 255.255.0.0 ppp1
export HOSTNAME="localhost.localdomain"
export SESSION_MANAGER="local/localhost.localdomain:/tmp/.ICE-unix/23350"
route add -host 163.195.16.155 netmask 255.255.0.0 ppp1
export HOSTNAME="localhost.localdomain"
export SESSION_MANAGER="local/localhost.localdomain:/tmp/.ICE-unix/23350"
route add -host 164.147.241.195 netmask 255.255.255.0 ppp1
export HOSTNAME="localhost.localdomain"
export SESSION_MANAGER="local/localhost.localdomain:/tmp/.ICE-unix/23350"
route add -host 196.6.240.2 netmask 255.255.255.0 ppp1
export HOSTNAME="localhost.localdomain"
export SESSION_MANAGER="local/localhost.localdomain:/tmp/.ICE-unix/23350"
route add -host 196.14.176.115 netmask 255.255.255.240 ppp1
export HOSTNAME="localhost.localdomain"
export SESSION_MANAGER="local/localhost.localdomain:/tmp/.ICE-unix/23350"
route add -host 196.23.48.244 netmask 255.255.255.240 ppp1
export HOSTNAME="localhost.localdomain"
export SESSION_MANAGER="local/localhost.localdomain:/tmp/.ICE-unix/23350"
route add -host 196.23.48.245 netmask 255.255.255.240 ppp1
export HOSTNAME="localhost.localdomain"
export SESSION_MANAGER="local/localhost.localdomain:/tmp/.ICE-unix/23350"
route add -host 196.34.16.71 netmask 255.255.255.224 ppp1
|
|
|
07-08-2007, 12:22 PM
|
#28
|
Senior Member
Registered: Aug 2003
Distribution: Debian Sid 32/64-bit, F10 32/64-bit
Posts: 1,070
Original Poster
Rep:
|
The solution is pretty easy actually.
Code:
cat newroutes.txt | while read route
do
export $(ipcalc -m $(echo $route | sed -e 's/^.*net\ \([0-9\.\/]*\).*$/\1/'))
echo $route | sed -e "s/\/[0-9]*/ netmask $NETMASK/"
done > incorrect.txt
cat incorrect.txt | grep route > correct.txt
correct.txt is as i expected it.
|
|
|
07-08-2007, 12:37 PM
|
#29
|
Moderator
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417
|
i've lost a bit of the track of this thread TBH, and from the output above, i'm not sure where those variables come from, currently too exhausted to look too!. Not that elegant a solution really though, should need an intermediate file should you?
Code:
cat newroutes.txt | while read route
do
export $(ipcalc -m $(echo $route | sed -e 's/^.*net\ \([0-9\.\/]*\).*$/\1/'))
echo $route | sed -e "s/\/[0-9]*/ netmask $NETMASK/"
done | grep route > correct.txt
or if it's actually the export line giving that additional output...
Code:
cat newroutes.txt | while read route
do
export $(ipcalc -m $(echo $route | sed -e 's/^.*net\ \([0-9\.\/]*\).*$/\1/')) > /dev/null
echo $route | sed -e "s/\/[0-9]*/ netmask $NETMASK/"
done > correct.txt
Last edited by acid_kewpie; 07-08-2007 at 12:40 PM.
|
|
|
All times are GMT -5. The time now is 09:51 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|