Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Server > Scripting > How do I run a batch file when a server reboots?

Reply
Thread Tools Display Modes

How do I run a batch file when a server reboots?

 
 
Marten
Guest
Posts: n/a

 
      08-06-2008
I have several servers that I have scheduled to reboot Sundays at 3
am. I'd like them to leave a mark that they did reboot as it seems
some don't always invoke the SHUTDOWN command.

I'd like to run a simple batch file that contains the line:

echo rebooted > \\primarycontoller\bootlogs$\%computername%.txt

The time stamp of the file will be enough to tell me if SHUTDOWN ran
properly.

My question is where do I put the call to this batch file so it gets
executed during the reboot?

Marten


 
Reply With Quote
 
 
 
 
Pegasus \(MVP\)
Guest
Posts: n/a

 
      08-06-2008

"Marten" <> wrote in message
news:...
>I have several servers that I have scheduled to reboot Sundays at 3
> am. I'd like them to leave a mark that they did reboot as it seems
> some don't always invoke the SHUTDOWN command.
>
> I'd like to run a simple batch file that contains the line:
>
> echo rebooted > \\primarycontoller\bootlogs$\%computername%.txt
>
> The time stamp of the file will be enough to tell me if SHUTDOWN ran
> properly.
>
> My question is where do I put the call to this batch file so it gets
> executed during the reboot?
>
> Marten
>


It seems you don't want to leave the mark for the ***boot-up***
event but rather for the ***shut-down*** event. Use the Task
Scheduler to invoke a batch file with two commands inside:
- Your "echo" command (probably supplemented with %date%
and %time%)
- shutdown.exe
You should also use the >> redirector so that subsequent
shutdown events do not overwrite the previous ones.


 
Reply With Quote
 
Marten
Guest
Posts: n/a

 
      08-06-2008
On Wed, 6 Aug 2008 19:54:47 +0200, "Pegasus \(MVP\)"
<> wrote:


>
>It seems you don't want to leave the mark for the ***boot-up***
>event but rather for the ***shut-down*** event. Use the Task
>Scheduler to invoke a batch file with two commands inside:
>- Your "echo" command (probably supplemented with %date%
> and %time%)
>- shutdown.exe
>You should also use the >> redirector so that subsequent
>shutdown events do not overwrite the previous ones.
>


That's a good method, thank you. I forgot to think of calling a batch
file from the scheduler.

My only concern is getting a false positive. By that I mean the first
line (per your suggestion) runs and creates the mark file, but for
what ever reason the Shutdown fails and the server doesn't reboot.
Which has happened. My thinking was if I could put the call to my
batch file in some equivalent of AUTOEXEC.BAT, I could be sure it was
processed during the power up.

The >> redirector is a consideration. I'm mostly concerned with thee
last reboot. But having a bit of history isn't bad. As long as I
remember to trim the file periodically.

for the record, the Shutdown command used is:
C:\WINDOWS\system32\shutdown.exe /r /d p:4:1

Marten
 
Reply With Quote
 
Pegasus \(MVP\)
Guest
Posts: n/a

 
      08-06-2008

"Marten" <> wrote in message
news:...
> On Wed, 6 Aug 2008 19:54:47 +0200, "Pegasus \(MVP\)"
> <> wrote:
>
>
>>
>>It seems you don't want to leave the mark for the ***boot-up***
>>event but rather for the ***shut-down*** event. Use the Task
>>Scheduler to invoke a batch file with two commands inside:
>>- Your "echo" command (probably supplemented with %date%
>> and %time%)
>>- shutdown.exe
>>You should also use the >> redirector so that subsequent
>>shutdown events do not overwrite the previous ones.
>>

>
> That's a good method, thank you. I forgot to think of calling a batch
> file from the scheduler.
>
> My only concern is getting a false positive. By that I mean the first
> line (per your suggestion) runs and creates the mark file, but for
> what ever reason the Shutdown fails and the server doesn't reboot.
> Which has happened. My thinking was if I could put the call to my
> batch file in some equivalent of AUTOEXEC.BAT, I could be sure it was
> processed during the power up.
>
> The >> redirector is a consideration. I'm mostly concerned with thee
> last reboot. But having a bit of history isn't bad. As long as I
> remember to trim the file periodically.
>
> for the record, the Shutdown command used is:
> C:\WINDOWS\system32\shutdown.exe /r /d p:4:1
>
> Marten


I'm quite aware of the syntax for the shutdown command . . .

Running a command at boot time (the equivalent of Autoexec.bat)
is dead easy: Use the Task Scheduler to run it at boot time.
However - how will you distinguish between a boot after a
scheduled shutdown and a boot caused by a crash?

About trimming the log file: If you schedule a reboot once every
week then you accumulate some 2 kBytes per annum. I would
not call this a huge amount of disk space - it's puny, so why worry?


 
Reply With Quote
 
Marten
Guest
Posts: n/a

 
      08-06-2008
On Wed, 6 Aug 2008 21:46:06 +0200, "Pegasus \(MVP\)"
<> wrote:


>> for the record, the Shutdown command used is:
>> C:\WINDOWS\system32\shutdown.exe /r /d p:4:1
>>
>> Marten

>
>I'm quite aware of the syntax for the shutdown command . . .
>
>Running a command at boot time (the equivalent of Autoexec.bat)
>is dead easy: Use the Task Scheduler to run it at boot time.
>However - how will you distinguish between a boot after a
>scheduled shutdown and a boot caused by a crash?
>
>About trimming the log file: If you schedule a reboot once every
>week then you accumulate some 2 kBytes per annum. I would
>not call this a huge amount of disk space - it's puny, so why worry?
>


My apologies for a grammatical error. I should have written "the
Shutdown command as I am using it is:" I added it in case you saw
something that was incorrect or if someone else reading this thread
wanted to know what I had done.

I haven't worked much with the scheduler. I wasn't aware there was an
at boot option. Thank you for pointing it out to me. As for
distinguishing, since I know the time of the scheduled reboot, I'd
expect anything outside that time frame would be questionable.

The >> redirect is a consideration. I was originally only concerned
with the last reboot.

Thank you for the information. It helps me out.

Marten
 
Reply With Quote
 
Pegasus \(MVP\)
Guest
Posts: n/a

 
      08-06-2008

"Marten" <> wrote in message
news:...
> On Wed, 6 Aug 2008 21:46:06 +0200, "Pegasus \(MVP\)"
> <> wrote:
>
>
>>> for the record, the Shutdown command used is:
>>> C:\WINDOWS\system32\shutdown.exe /r /d p:4:1
>>>
>>> Marten

>>
>>I'm quite aware of the syntax for the shutdown command . . .
>>
>>Running a command at boot time (the equivalent of Autoexec.bat)
>>is dead easy: Use the Task Scheduler to run it at boot time.
>>However - how will you distinguish between a boot after a
>>scheduled shutdown and a boot caused by a crash?
>>
>>About trimming the log file: If you schedule a reboot once every
>>week then you accumulate some 2 kBytes per annum. I would
>>not call this a huge amount of disk space - it's puny, so why worry?
>>

>
> My apologies for a grammatical error. I should have written "the
> Shutdown command as I am using it is:" I added it in case you saw
> something that was incorrect or if someone else reading this thread
> wanted to know what I had done.
>
> I haven't worked much with the scheduler. I wasn't aware there was an
> at boot option. Thank you for pointing it out to me. As for
> distinguishing, since I know the time of the scheduled reboot, I'd
> expect anything outside that time frame would be questionable.
>
> The >> redirect is a consideration. I was originally only concerned
> with the last reboot.
>
> Thank you for the information. It helps me out.
>
> Marten


Thanks for the feedack.


 
Reply With Quote
 
Greg Stigers
Guest
Posts: n/a

 
      08-08-2008
Aren't the events in the event log enough of a mark?
______
Greg Stigers, MCSE
remember to vote for the answers you like


 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
run script/batch file on remote pc from a server Danc383@hotmail.com Scripting 2 12-10-2007 10:52 PM
Run batch file on remote server PeteL Windows Server 6 09-25-2007 03:42 PM
can I run a batch file on the server, from a workstation? MDBJ Windows Small Business Server 2 03-01-2006 01:06 PM
Batch file and scheduler on Server FL Consultant Windows Server 10 07-28-2005 03:17 PM
Running FTP Batch file on server Steve McGrath Windows Small Business Server 3 03-04-2005 05:13 AM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59