Hi,

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
ganeshanbu
Posts: 2
Joined: 23 Dec 2010 12:19

Hi,

#1 Post by ganeshanbu » 23 Dec 2010 12:31

I am new to the Dos Scripting,

I need small script which is equivalent to the shell scripting.

Description of the script -> below script use to restart the server.

$cat a.sh
cd / # change directory to root
net stop "OneBridge Sync Server" > a.log # command which used to stop the server
if [ $? = 0 ] # checking whether the last command is success or not
then
net start "OneBridge Sync Server" >> a.log # if stop is success then start the server
if [ $? = 0 ]
then
mailx -s "Successfully restarted" <mailid> < a.log # sending mail for success of restart
else
mailx -s "Failure of starting" <mailid> < a.log # failure while starting
fi
else
mailx -s "Failure of stopping" <mailid> < a.log # failure while stopping
fi

Please provide the equivalent Dos Script.

By
Ganesh.

ChickenSoup
Posts: 79
Joined: 13 Dec 2010 10:32

Re: Hi,

#2 Post by ChickenSoup » 27 Dec 2010 16:08

This should do it for you.

Code: Select all

net stop "OneBridge Sync Server" >nul 2>&1
if %errorlevel%==0 (
   net start "OneBridge Sync Server" >nul 2>&1
   if %errorlevel%==0 (
      echo.Successfully restarted
   ) else (
      echo.Failure of starting
   )
) else (
   echo.Failure of stopping
)

ghostmachine4
Posts: 319
Joined: 12 May 2006 01:13

Re: Hi,

#3 Post by ghostmachine4 » 27 Dec 2010 19:00

ChickenSoup wrote:This should do it for you.

Code: Select all

net stop "OneBridge Sync Server" >nul 2>&1
if %errorlevel%==0 (
   net start "OneBridge Sync Server" >nul 2>&1
   if %errorlevel%==0 (
      echo.Successfully restarted
   ) else (
      echo.Failure of starting
   )
) else (
   echo.Failure of stopping
)


he wants to direct the output of net stop to a.log file, not nul . You should also mention the mail command to use in batch ( eg blat etc) so that he can send his log file via email

ChickenSoup
Posts: 79
Joined: 13 Dec 2010 10:32

Re: Hi,

#4 Post by ChickenSoup » 28 Dec 2010 07:40

Well, I at least gave them a starting point. Nobody else did. I missed that they wanted the actual output logged (I updated this below). Feel free to edit my script to help them out. I don't know of anything native in batch that sends emails. I assumed that they could handle finding this.

Code: Select all

net stop "OneBridge Sync Server" >a.log 2>&1
if %errorlevel%==0 (
   net start "OneBridge Sync Server" >a.log 2>&1
   if %errorlevel%==0 (
      echo.Successfully restarted
   ) else (
      echo.Failure of starting
   )
) else (
   echo.Failure of stopping
)

Post Reply