Script

Can somebody revise this script to run successfully and also correct the "route add" command?

@echo off

echo Adding route
echo ===================================================
echo
route route add 192.168.60.10 mask 255.255.255.0 192.168.60.1 Metric 10 IF 2

echo Route Added
klajdiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nociSoftware EngineerCommented:
For what platform: Dos?, Unix?, Windows?
What language:  BAT, CMD, Perl, Bash, ????

For windows there seems no need for change? Or what is wrong on that line, the address, netmask, gateway address or interface?
For address there are about 4 billion choices, where only a few will actualy work, depending on netmask the gateway is a subset of those address range.


In short: Your question is:   "Do something"  which is a bit vague.
There is no syntax error in your script if it is meant for windows. if the other information is right depends on your system/environment.

So please indicate what doesn't work
0
digusCommented:
Maybe change "route route add 192.168.60.10 mask 255.255.255.0 192.168.60.1 Metric 10 IF 2"

to:

 "route add 192.168.60.10 mask 255.255.255.0 192.168.60.1 Metric 10 IF 2"
?
0
nociSoftware EngineerCommented:
I didn't see the route route... part...
0
ON-DEMAND: 10 Easy Ways to Lose a Password

Learn about the methods that hackers use to lift real, working credentials from even the most security-savvy employees in this on-demand webinar. We cover the importance of multi-factor authentication and how these solutions can better protect your business!

klajdiAuthor Commented:
I meant to make it to run only one time and not because it keeps going in infinite loop and also as static route?
0
mikebernhardtCommented:
Is that the actual script or just an example? Because trying to get to 192.168.60.10 via 192.168.60.1 is a useless exercise. The router is just going to tell the workstation to go directly to 60.10 with an ICMP redirect message.

As far as being in a loop, try adding a line with the word "end" at the end.
0
mikebernhardtCommented:
Why is the word "route" there twice?
0
digusCommented:
"route add 192.168.60.10 mask 255.255.255.255 192.168.61.1 Metric 10 -p"

the -p is for persistent (across reboots).

Now, your example will not work for a couple of reasons. 255.255.255.0 is not a valid subnet mask for a single host (it's only valid for a class C subnet - 254 hosts). Also, there is usually no need to specify the "IF" parameter.

For the single host route (like in your example), "route add 192.168.60.10 mask 255.255.255.255 192.168.61.1 Metric 10 -p" would work. Notice the 255.255.255.255 mask for a single host. Notice also that it impossible to add a route to the subnet you are already on. Above, I have pointed the route to the 192.168.61.1 gateway. Your example would fail because you are trying to route a host to a network it's already on.

If you want to route the whole subnet, change the address and mask: "route add 192.168.60.0 mask 255.255.255.0 192.168.61.1 Metric 10 -p"

Make sense? If you are still having problems, remove the "@ECHO OFF" line and add the "pause" command to the very bottom of the script. This will allow you to see any errors and report them back here.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nociSoftware EngineerCommented:
@digus, that's what I meant a bunch of inconsistent data, and no target for what is meant.
DWIM (Do What I Mean) are hard to answer questions.
0
digusCommented:
hehe - no doubt.
0
klajdiAuthor Commented:
Attached is the image from Route Print from windows server 2003 with 2 network cards.

So i typed the command that Digus gave, are the changes reflected there? Is the route created
screen.PNG
0
digusCommented:
If you used the exact command(s) I gave, then it doesn't look like it worked (because my examples used a 192.168.61.1 gateway - which doesn't exist in your config). Also, there are no persistent routes at the bottom, but there should be if you used the "-p" at the end of the command, and if it completed successfully. So, lets try a new subnet with your real gateway this time.

Give this script a try and post the image/output for us:


echo Adding route(s)
echo ===================================================
route add 192.168.66.10 mask 255.255.255.255 192.168.60.1 Metric 10 -p
route add 192.168.166.0 mask 255.255.255.0 192.168.60.1 Metric 10 -p

echo Route Added
pause
0
klajdiAuthor Commented:
Attached are the results. I believe the persistent route still is not added.
screen2.PNG
0
digusCommented:
No, it's not persistent. I've tested this on a 2003 box though, and it worked for me, with the "-p" adding them as persistent.

The output from the example script I posted above is about the only way I'll be able to see what's actually going on. I'm not sure exactly what commands you're running, but I know they are not the ones from the script I posted above.
0
klajdiAuthor Commented:
Digus thanks a lot it worked fine now. I can see the persistent routes.
0
digusCommented:
Awesome - you're welcome!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Network Management

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.