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.
Hi,
Moderator: DosItHelp
-
- Posts: 79
- Joined: 13 Dec 2010 10:32
Re: Hi,
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
)
-
- Posts: 319
- Joined: 12 May 2006 01:13
Re: Hi,
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
-
- Posts: 79
- Joined: 13 Dec 2010 10:32
Re: Hi,
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
)