Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Batch file script to connect to VPN run program then disconnect

2,220 views
Skip to first unread message

sto...@hotmail.com

unread,
Jul 25, 2005, 11:51:05 AM7/25/05
to
Hi,


I'm in a bit a a jam. I need to make a bat file that can do the
following.


1) Connect to VPN - Code : "rasphone -d "VPN connection name"
2) Wait 5 secs
3) Test connection through VPN (ping ip address)
4) If Ping is connects then run goto (5) otherwise goto (8) or wait
10sec then test again
5) Shutdown SQL instance - "SERVERNAME\instancename"
6) run backup program and wait for it to quit code:
"C:\program\backupapp.exe"
7) Start up SQL instance - "SERVERNAME\instancename"
8) Disconnect from VPN - Code: :rasphone -h "VPN connection name"


Any help would be a life saver!!! I don't know where to start!


thank you

Todd Vargo

unread,
Jul 25, 2005, 6:15:22 PM7/25/05
to

<sto...@hotmail.com> wrote in message
news:1122306665.1...@g47g2000cwa.googlegroups.com...

Now that you are posting to the correct group, most of what you want to do
has been posted already. Have you considered reading some of the existing
posts before asking others to do all your work for you? Try doing some of
the work in advance so you only need help with one or two parts. State which
parts you know already and show the code you have written so far.

--
Todd Vargo (double "L" to reply by email)

sto...@hotmail.com

unread,
Jul 25, 2005, 10:31:48 PM7/25/05
to
Todd,

I have read other posts, and I made a post b/c I could not find the
solution in the forum. If you noticed, I included the parts I could
find. I was starting from ground zero. But after I spent all day I
found a great website that helped me.

AN EXTREMELY HELPFUL website is.....http://www.robvanderwoude.com/

I figured out the answer all that I orginally posted from this website.


Thank you for your extremely helpful and kind words.

But since you offered some advice, I would like to offer some.

Instead of making unhelpful comments, rather just state the solution,
and if you don't know it, then don't comment. It just clogs the forum.
After all these forums are made to request help. That's the whole
purpose, post a question get an answer, know an answer post an answer.

Have a good night!

The general solution is below for anyone that can find this helpful.
It's not perfect or tested yet, but the general idea in code is below.
I learned that you can code a batch file like any other programming
language, which I did not know. You can include loops and calculations
and IF statements. There are only a few commands, but you can really
do a lot with them.


rasphone -d "VPN connection name"

:loop

ping SERVER -w 5000 -n 1 | FIND "TTL">NUL
IF ERRORLEVEL 1 GOTO loop

NET STOP MSSQL$MyInstance

start /w "C:\program\backupapp.exe"

NET START MSSQL$MyInstance

Al Dunbar

unread,
Jul 25, 2005, 11:46:39 PM7/25/05
to

<sto...@hotmail.com> wrote in message
news:1122306665.1...@g47g2000cwa.googlegroups.com...

Where to start? - Start by breaking this rather detailed task down into a
series of smaller tasks. Once the tasks are small enough, just solve each
one individually. Once you have the parts working, then work on integrating
them into the script you want.

To get you started (well, actually, *you* started by doing the first thing I
suggested...):

> 1) Connect to VPN - Code : "rasphone -d "VPN connection name"

Sorry, not sure...

> 2) Wait 5 secs

:wait5sec
>nul ping -n 6 localhost

> 3) Test connection through VPN (ping ip address)
> 4) If Ping is connects then run goto (5) otherwise goto (8) or wait
> 10sec then test again

determining if a host is there based on the output of the ping command has
been done to death here. In brief:

(set/p IP=enter IP address, as Al does not know what you want to ping: )
ping %IP% | find "TTL=" >nul
if errorlevel 1 goto:wait5sec

> 5) Shutdown SQL instance - "SERVERNAME\instancename"
> 6) run backup program and wait for it to quit code:
> "C:\program\backupapp.exe"
> 7) Start up SQL instance - "SERVERNAME\instancename"
> 8) Disconnect from VPN - Code: :rasphone -h "VPN connection name"


Sorry, not sure...


/Al


Al Dunbar

unread,
Jul 25, 2005, 11:56:13 PM7/25/05
to

<sto...@hotmail.com> wrote in message
news:1122345108....@f14g2000cwb.googlegroups.com...

> Todd,
>
> I have read other posts, and I made a post b/c I could not find the
> solution in the forum. If you noticed, I included the parts I could
> find. I was starting from ground zero. But after I spent all day I
> found a great website that helped me.
>
> AN EXTREMELY HELPFUL website is.....http://www.robvanderwoude.com/
>
> I figured out the answer all that I orginally posted from this website.
>
>
> Thank you for your extremely helpful and kind words.
>
> But since you offered some advice, I would like to offer some.
>
> Instead of making unhelpful comments, rather just state the solution,
> and if you don't know it, then don't comment. It just clogs the forum.
> After all these forums are made to request help. That's the whole
> purpose, post a question get an answer, know an answer post an answer.

Todd's response might have seemed terse, but it was only aimed at helping
you get the answers you are looking for. Quoting him, now, then:

> Now that you are posting to the correct group, most of what you want to do
> has been posted already.

For one example, using ping to determine if a device is available.

> Have you considered reading some of the existing
> posts before asking others to do all your work for you?

OK, this could have been stated more diplomatically, but really, it seemed
to me as well that you hadn't looked, because the things you were asking
about have been asked and answered countless times.

But the fact remains, you did seem to be asking for the whole thing to be
handed to you.

> Try doing some of
> the work in advance so you only need help with one or two parts.

You listed a series of tasks and basically said you had no idea...

> State which
> parts you know already and show the code you have written so far.

Had you done so, you would no doubt have had more success getting help. This
is not because we demand it of you; rather, it's just a matter of giving as
much useful information as you can to those who are taking the time to read
your questions.

/Al

sto...@hotmail.com

unread,
Jul 26, 2005, 10:05:54 AM7/26/05
to
AI,

Thanks for being diplomatic. As stated, I found the answer and posted
it. I hope it's helpful to others. Tasks like this are really easy if
you know the answer. I was hoping to find someone that did. Rather
than waste my full day looking for it. Yet, I did waste my full day
and found the answer. It really comes down to me hoping not to waste my
full day. I orginally spent two hours looking for an answer then
posted. THen I spent the rest of the day researching some more. I was
not trying to get some one to do my work, rather, you learn from
others, being it written, oral, or some other media. If some one know
the answer I hoped they could share it.

As stated, I think this task ended up being much more simple then I
orginally thought. But now that I have some knowledge on the subject.
I am more then willing to help when needed.

Cheers!!

Todd Vargo

unread,
Jul 26, 2005, 6:58:54 PM7/26/05
to

<sto...@hotmail.com> wrote:

> Todd,


>
> Instead of making unhelpful comments, rather just state the solution,
> and if you don't know it, then don't comment. It just clogs the forum.
> After all these forums are made to request help. That's the whole
> purpose, post a question get an answer, know an answer post an answer.

FYI, these are discussion groups and the best advise anyone can give another
is to try first. Now, commenting on your post to Al, you did not waste your
time. You learned something more valuable than someone giving you a free
answer. You learned to research your subject and solve your own problem.

Honestly, it appeared you had most of the information already in hand. BTW,
I would suggest including a time-out in the loop so in case the connection
fails, the batch can terminate gracefully. The following allows it to loop 5
times before giving up rather then looping endlessly with a dead connection.

set count=0
:loop
set /a count+=1
if %count%==5 goto :abort


ping SERVER -w 5000 -n 1 | FIND "TTL">NUL
IF ERRORLEVEL 1 GOTO loop

--

Al Dunbar

unread,
Jul 26, 2005, 10:47:43 PM7/26/05
to

<sto...@hotmail.com> wrote in message
news:1122386754....@g43g2000cwa.googlegroups.com...

> AI,
>
> Thanks for being diplomatic. As stated, I found the answer and posted
> it. I hope it's helpful to others. Tasks like this are really easy if
> you know the answer. I was hoping to find someone that did. Rather
> than waste my full day looking for it. Yet, I did waste my full day
> and found the answer. It really comes down to me hoping not to waste my
> full day.

As Todd said elsethread, you did not waste your day. And, if it took you a
day, while ten of us each spent, say, an hour working towards a solution,
you would be the one to have spent less time.

That said, the next time you have a problem such as this, your experience
will cause you to waste (sorry, I meant to say *use*) even less time finding
the solution.

> I orginally spent two hours looking for an answer then
> posted. THen I spent the rest of the day researching some more. I was
> not trying to get some one to do my work, rather, you learn from
> others, being it written, oral, or some other media.

Hey, we know how these here newsgroups work. Todd and I have been here doing
this for at least a couple of years each.

> If some one know
> the answer I hoped they could share it.

Part of the problem we face when wanting to give an answer is not really
knowing the scope of the question. If is much, much easier for us to deal
with distinct aspects of the problem than the whole shebang all at once. And
far easier to give effective assistance when we have a better idea of what
the individual does know on the subject.

Some people tend to give complete solutions, whereas I almost never do. I
have seen complete answers given in quite a few situtations where it turned
out the question was misunderstood, and the helper's time basically wasted.
I usually try to help determine exactly what the issues are before I commit
much time to working on the solution.

> As stated, I think this task ended up being much more simple then I
> orginally thought. But now that I have some knowledge on the subject.
> I am more then willing to help when needed.

But how did you come to this state? Was it not by doing more of the work
yourself, somewhat along the lines of what Todd was suggesting?

/Al


0 new messages