Re: Startup Script but wait for SQL to start

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Have a look at the following lines:

echo %date% %time% %UserName% (Loop) >> c:\test.txt
echo %date% %time% %UserName% (After Loop) >> c:\test.txt

Wed 04/08/2009 12:20:55.45 (Main script)
Wed 04/08/2009 12:20:55.51 (Loop)

In each case there is supposed to be a Username in the log file. Where is
it? Its absence suggests that you run the scheduled task under a System
account, perhaps using at.exe. How about adopting the standard approach and
creating a dedicated account to be used by the Task Scheduler only, then
running the job under that account? Make sure the account has sufficient
privileges to do what it needs to do.

If this makes no difference then it's time to go right down to basics.


"Steve Ikard" <SteveIkard@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:E2E8A611-2876-46FE-A904-A180FF63E7C0@xxxxxxxxxxxxxxxx
Still don't see enough to be able to figure out what's wrong.

Main batch file (StartupScript.bat):
@echo off
echo %date% %time% %UserName% (Main script) >>c:\test.txt
start /b "Indexer" "E:\Tools\StartTMIndexer.bat"

2nd batch file (StartTMIndexer.bat):
@echo off
:Loop
echo %date% %time% %UserName% (Loop) >> c:\test.txt
ping localhost -n 30 1>>c:test.txt 2>>&1
net start | find /i "MSSQLSERVER" 1>>c:test.txt 2>>&1
if Errorlevel 1 goto Loop
echo %date% %time% %UserName% (After Loop) >> c:\test.txt
\\IC-SBS2003\Apps\tmw9e\tmdatndxe.exe /data=\\IC-SBS2003\Apps\tmw9e\Data
1>>c:\test.txt 2>>&1

When I test from GP Startup Script here is what test.txt contains:
Wed 04/08/2009 12:20:55.45 (Main script)
Wed 04/08/2009 12:20:55.51 (Loop)

And it does not start up my Indexer program -- since I guess it never gets
to the "After Loop" stmt.

When I test from CMD here is what test.txt contains:
Wed 04/08/2009 13:22:32.65 administrator (Main script)
Wed 04/08/2009 13:22:32.67 administrator (Loop)
Wed 04/08/2009 13:23:01.75 administrator (After Loop)

And it sucessfully starts up the Indexer.

The lines that you had me add "1>>c:\test.txt 2>>&1" don't show anything
in
test.txt. Do I have the syntax correct? What exactly are they supposed
to
show?

Thanks, again, for your patience in helping me solve this problem. There
are a lot of users who could benefit from the Indexer starting up
automatically at server boot up time.



"Pegasus [MVP]" wrote:

A couple of observations:
- If you see only one single log line of the form
Mon 04/06/2009 16:35:19.09 (Loop)
then the program hangs inside the loop. Otherwise
there should me many of these messages! You now
need to debug the loop, e.g. like so:
1. @echo off
2. :Loop
3. echo %date% %time% %UserName% (Loop) >> c:\test.txt
4. ping localhost -n 30 1>>c:\test.txt 2>>&1
5. net start |find /i "MSSQLSERVER" 1>>c:\test.txt 2>>&1
6. if Errorlevel 1 goto Loop
7. echo %date% %time% %UserName% (After loop) >> c:\test.txt
8. \\ic-sbs2003\apps\tmw9e\tmdatndxe.exe
/data=\\ic-sbs2003\Apps\tmw9e\Data
1>>c:\test.txt 2>>&1

Your question about the last line: Well, I tried very hard to number each
line of code so that you could see clearly where each of them starts and
ends, which is important when your newsreader wraps long lines.
Unfortunately this did not prevent you from considering the last line as
a
separate line. It isn't - it is the tail end of Line 8! Its purpose is to
capture standard and error output in our log file c:\test.txt.


"Steve Ikard" <SteveIkard@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:104DF28F-A025-4965-96FF-BAF0ADD34D96@xxxxxxxxxxxxxxxx
Thanks for getting back to me on Friday night. I have been away so
this
is
my first chance to get back to this problem. The test.txt says...
Mon 04/06/2009 16:35:19.03 (Main script)
Mon 04/06/2009 16:35:19.09 (Loop)

And that's all. It never gets to the "(After Loop)" so it never starts
the
indexer program.

BTW, what does the last line do? ("1>>c:\test.txt 2>>&1")


"Pegasus [MVP]" wrote:


"Steve Ikard" <SteveIkard@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:5C5B820A-8C1A-4014-974E-9DC790ADC685@xxxxxxxxxxxxxxxx
OK, I opened up a Command Prompt screen and ran StartupScript.bat.
(I
Rem'd
echo off in both batch files so I could see what was going on.) It
sucessfully called StartTMIndexer.bat. It started the Indexer just
fine.
When I used the executable line without the "start /b" it did what
you
had
questioned -- tmdatndxe.exe prevented the calling batch file from
closing.
I
changed the line to "start /b "" \\ic=sbs2003\Apps......" and it
worked
fine.

So, I'm still left wondering why it won't work in the Group Policy
Startup
Script...

You now add some debugging code like so:
@echo off
echo %date% %time% %UserName% (Main script) >> c:\test.txt
start /b "Indexer" "E:\Tools\StartTMIndexer.bat"

The file E:\Tools\StartTMIndexer.bat must contain these lines:
1. @echo off
2. :Loop
3. echo %date% %time% %UserName% (Loop) >> c:\test.txt
4. ping localhost -n 30 > nul
5. net start |find /i "MSSQLSERVER" || Goto Loop
6. echo %date% %time% %UserName% (After loop) >> c:\test.txt
7. \\ic-sbs2003\apps\tmw9e\tmdatndxe.exe
/data=\\ic-sbs2003\Apps\tmw9e\Data
1>>c:\test.txt 2>>&1

I have added line numbers so that you can see where each new line
starts.

What does the log file c:\test.txt report?








.



Relevant Pages

  • Re: Startup Script but wait for SQL to start
    ... Main batch file: ... @echo off ... if Errorlevel 1 goto Loop ... And it sucessfully starts up the Indexer. ...
    (microsoft.public.windows.server.general)
  • Re: Parsing the appended data of log file in real time
    ... When peek doesnt return any data then sit in an idle loop till it does.. ... Actually another application is writing to the log file. ... 'scriptInAction is the control vairiable for the do util loop while ... currentLine = logFile.ReadLine ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Reading a variable line by line with while loop
    ... done < `echo "$Variable"` ... echo "History - $History" ... The last echo command returns nothing, but if I put an echo command in ... the loop either before, or after the replace spaces command, it echoes ...
    (Ubuntu)
  • Re: 2.6.16-rc4: known regressions
    ... either with a command line argument, or with just the early bootup initrd ... Is there a way to tell the kernel about which is the root device other ... a loop with one second delay. ... echo -n "Waiting for root device to appear" ...
    (Linux-Kernel)
  • Re: [PHP] 2 errors I can not understand
    ... echo is not a function. ... multiple args is probably insignificant, ... and super-long loop... ... function isprime ...
    (php.general)