Page 1 of 1

Hi,

Posted: 23 Dec 2010 12:31
by ganeshanbu
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.

Re: Hi,

Posted: 27 Dec 2010 16:08
by ChickenSoup
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
)

Re: Hi,

Posted: 27 Dec 2010 19:00
by ghostmachine4
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

Re: Hi,

Posted: 28 Dec 2010 07:40
by ChickenSoup
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
)