[BATCH] An example of re-booting cycling with traces tracking down

An overview of reboot cycling script.

A top directory called rebooter designed by user

[BATCH] An example of re-booting cycling with traces tracking 
down

A sub-directory call Reboot

[BATCH] An example of re-booting cycling with traces tracking 
down

 1. Reboot_run.bat =>this is a startup script used for full script copying from current dictionary to c:\reboot

[BATCH] An example of re-booting cycling with traces tracking 
down
1 @echo off
2 set ROOT_DIR=%~dp0
3 set TOOL_SRC=%ROOT_DIR%
4 set TOOL_DES=C:5 xcopy %TOOL_SRC%\reboot\* %TOOL_DES%\Reboot\ /e /i /y
6 Start %TOOL_DES%\reboot\begin.bat
[BATCH] An example of re-booting cycling with traces tracking 
down

2. begin.bat => do some initialization including desired interation inputed by user, startup.bat registering at
HKLM\Software\Microsoft\Windows\CurrentVersion\Run so that this can be boot up while system powering up.

[BATCH] An example of re-booting cycling with traces tracking 
down
 1 @echo off
 2 set REG=C:\reboot\Enable_Autorun.reg
 3 
 4 :begin
 5 @set /p reboot= How many reboot cycles do you need:
 6 if %reboot% LSS 0 (@echo Please enter a value greater than or equal to 0) else (goto :continue)
 7 if %reboot% LSS 0 (goto :begin)
 8 
 9 :continue
10 @echo You Have selected it to reboot for %reboot% times >>c:\reboot\reboot.log
11 @echo ------------------------------------------------- >>c:\reboot\reboot.log
12 @echo %reboot% >c:\reboot\counter.txt
13 copy c:\reboot\counter.txt c:\reboot\count.txt /y
14 
15 REM REG ADD HKLM\Software\Microsoft\Windows\CurrentVersion\Run /v Reboot /t REG_SZ /d c:\reboot\startup.bat
16 regedit /s %REG%
17 echo y | REG ADD HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System /v EnableLUA /t REG_DWORD /d 0
18 call c:\reboot\startup.bat
[BATCH] An example of re-booting cycling with traces tracking 
down

3. startup.bat => this is main script used for cycle iteration on invoking fail_result.bat to analyse the logfile each time
and make a judgement on whether the disired cycle is reached up, if so, clearng all log formed inbetween in the course of script execution.

 

[BATCH] An example of re-booting cycling with traces tracking 
down
 1 set LOG=C:\reboot\reboot.log
 2 set CNT=C:\reboot\counter.txt
 3 set CNTCOPY=c:\reboot\count.txt
 4 set SEC=20
 5 
 6 REM counter counter decrease as rebooting action performing
 7 set /p counter=<%CNT%
 8 set /a counter=%counter%-1
 9 REM count increment for reboot cycling tracking down.
10 set /p count=<%CNTCOPY%
11 set /a count=(%count%-%counter%)
12 echo %counter% >%CNT%
13 
14 if %counter% LEQ -1 (goto :cleanup) else (goto :restart)
15 :restart
16 echo waiting for 20 sec for reboot cycling
17 @timeout %SEC% >nul
18 cd /d c:\reboot
19 echo. >> result.txt
20 echo Time stamp at %count% reboots: %date% %time% >>result.txt
21 echo Time stamp at %count% reboots: %date% %time% >>%LOG%
22 devcon.exe status * > devinfo.txt
23 call C:\reboot\fail_result.bat
24 shutdown -r -t 0 -f
25 goto :end
26 :cleanup
27 c:\reboot\cleanup.cmd
28 :end
[BATCH] An example of re-booting cycling with traces tracking 
down

4. fail_result.bat

[BATCH] An example of re-booting cycling with traces tracking 
down
 1 @echo off
 2 setlocal enabledelayedexpansion
 3 REM devcon.exe status * >devinfo.txt
 4 for /f "delims=: tokens=1,*" %%i in (‘findstr /n /c:"Device has a problem" devinfo.txt‘) do (
 5     echo %%j>>result.txt
 6     set  flag=1
 7     set  line=%%i
 8     call :twoline 
 9 )
10 goto :eof
11 
12 :twoline
13     set /a line=line-1
14     for /f "tokens=1,* delims=:" %%i in (‘findstr /n .* devinfo.txt‘) do (
15     if  %line% equ %%i  (
16     echo %%j>>result.txt 
17 
18     if %flag% ==1 (
19         set flag=0
20         goto :twoline
21         )   else (goto :eof)
22     
23 
24 )
25 )
[BATCH] An example of re-booting cycling with traces tracking 
down

5. cleanup.cmd

[BATCH] An example of re-booting cycling with traces tracking 
down
 1 @echo off
 2 
 3 set REG=C:\reboot\disable_Autorun.reg
 4 regedit /s %REG%
 5 
 6 del /q c:\reboot\count.txt
 7 del /q c:\reboot\counter.txt
 8 
 9 echo y | REG ADD HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System /v EnableLUA /t REG_DWORD /d 1
10 echo please enter any key to complete cleanup.
11 pause 1>nul
[BATCH] An example of re-booting cycling with traces tracking 
down

6. Disable_Autorun.reg

1 Windows Registry Editor Version 5.00
2 
3 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run]
4 "rebooter"="C:\\reboot"

7. Enable_Autorun.reg

1 Windows Registry Editor Version 5.00
2 
3 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run]
4 "Rebooter"="C:\\Reboot\\Startup.bat"

[BATCH] An example of re-booting cycling with traces tracking down

上一篇:centos 命令


下一篇:服务器远程管理