2013-07-12 2 views
0

입니다 볼 수 신선한 눈이 필요합니다. 나는 그것을 찾지 못할 것입니다. 그리고 저는 새로운 눈 세트를 발견 할 수 있습니다.배치 : 나는 오류가 나는 <strong>누락 피연산자</strong> 오류가 계속

@echo off 

title Log Split And Backup 

rem dt = date 
rem tm = time 
rem wd = week day 
rem mh = month 
rem dy = day 
rem yr = year 
rem hh = hour 
rem mm = minute 
rem ss = second 
rem ms = milisecond 
rem gtr = greater than 
rem lss = less than 
rem equ = equal to 

echo Starting Log Split And Backup... 
ping 1.1.1.1 -n 1 -w 1500 >nul 
cls 
echo Log Split And Backup Has Started... 

:time 
set hh=%tm:~0,2% 
set mm=%tm:~3,2% 
set ss=%tm:~5,2% 
set ms=%tm:~7,2% 
goto date 

:date 
set dt=%date% 
set tm=%time% 
set wd=%dt:~0,3% 
set mh=%dt:~4,2% 
set dy=%dt:~6,2% 
set yr=%dt:~8,4% 
goto scheduletimes 

:scheduletimes 
:hour1 
for /f "tokens=1*delims=0" %%a in ("$0%hh%") do set /a HH=%%b 
if %HH% equ 6 goto minutes1 
goto hour2 
:minutes1 
for /f "tokens=1*delims=0" %%a in ("$0%hh%") do set /a HH=%%b 
if %HH% equ 0 goto seconds1 
goto hour2 
:seconds1 
for /f "tokens=1*delims=0" %%a in ("$0%hh%") do set /a HH=%%b 
if %HH% lss 10 goto day1 
goto hour2 
:hour2 
for /f "tokens=1*delims=0" %%a in ("$0%hh%") do set /a HH=%%b 
if %HH% equ 18 goto minutes2 
goto time 
:minutes2 
for /f "tokens=1*delims=0" %%a in ("$0%hh%") do set /a HH=%%b 
if %HH% equ 0 goto seconds2 
goto time 
:seconds2 
for /f "tokens=1*delims=0" %%a in ("$0%hh%") do set /a HH=%%b 
if %HH% lss 10 goto day2 
goto time 

:days 
:day1 
for %%i in (Mon) do (
    if "%wd%"=="%%i" goto mon1 
) 
for %%i in (Tue) do (
    if "%wd%"=="%%i" goto tue1 
) 
for %%i in (Wed) do (
    if "%wd%"=="%%i" goto wed1 
) 
for %%i in (Thu) do (
    if "%wd%"=="%%i" goto thu1 
) 
for %%i in (Fri) do (
    if "%wd%"=="%%i" goto fri1 
) 
for %%i in (Sat) do (
    if "%wd%"=="%%i" goto sat1 
) 
for %%i in (Sun) do (
    if "%wd%"=="%%i" goto sun1 
) 

:day2 
for %%i in (Mon) do (
    if "%wd%"=="%%i" goto mon2 
) 
for %%i in (Tue) do (
    if "%wd%"=="%%i" goto tue2 
) 
for %%i in (Wed) do (
    if "%wd%"=="%%i" goto wed2 
) 
for %%i in (Thu) do (
    if "%wd%"=="%%i" goto thu2 
) 
for %%i in (Fri) do (
    if "%wd%"=="%%i" goto fri2 
) 
for %%i in (Sat) do (
    if "%wd%"=="%%i" goto sat2 
) 
for %%i in (Sun) do (
    if "%wd%"=="%%i" goto sun2 
) 

:logsplitting 
:mon1 
@echo %date% 
@echo %time% 
echo Starting the 12hr Log Split and Log Backup... 
ping 1.1.1.1 -n 1 -w 3000 >nul 
xcopy "C:\Users\Kratos\Desktop\MC Server\server.txt" "C:\Users\Kratos\Dropbox\Minecraft Backups\Logs\0-mon\server1.txt" /D /E /R /I /K /Y    
del "C:\Users\Kratos\Desktop\MC Server\server.txt" 
echo Finished Log Split and Log Backup... 
goto time 
:tue1 
@echo %date% 
@echo %time% 
echo Starting the 12hr Log Split and Log Backup... 
ping 1.1.1.1 -n 1 -w 3000 >nul 
xcopy "C:\Users\Kratos\Desktop\MC Server\server.txt" "C:\Users\Kratos\Dropbox\Minecraft Backups\Logs\1-tue\server1.txt" /D /E /R /I /K /Y 
del "C:\Users\Kratos\Desktop\MC Server\server.txt" 
echo Finished Log Split and Log Backup... 
goto time 
:wed1 
@echo %date% 
@echo %time% 
echo Starting the 12hr Log Split and Log Backup... 
ping 1.1.1.1 -n 1 -w 3000 >nul 
xcopy "C:\Users\Kratos\Desktop\MC Server\server.txt" "C:\Users\Kratos\Dropbox\Minecraft Backups\Logs\2-wed\server1.txt" /D /E /R /I /K /Y 
del "C:\Users\Kratos\Desktop\MC Server\server.txt" 
echo Finished Log Split and Log Backup... 
goto time 
:thu1 
@echo %date% 
@echo %time% 
echo Starting the 12hr Log Split and Log Backup... 
ping 1.1.1.1 -n 1 -w 3000 >nul 
xcopy "C:\Users\Kratos\Desktop\MC Server\server.txt" "C:\Users\Kratos\Dropbox\Minecraft Backups\Logs\3-thu\server1.txt" /D /E /R /I /K /Y 
del "C:\Users\Kratos\Desktop\MC Server\server.txt" 
echo Finished Log Split and Log Backup... 
goto time 
:fri1 
@echo %date% 
@echo %time% 
echo Starting the 12hr Log Split and Log Backup... 
ping 1.1.1.1 -n 1 -w 3000 >nul 
xcopy "C:\Users\Kratos\Desktop\MC Server\server.txt" "C:\Users\Kratos\Dropbox\Minecraft Backups\Logs\4-fri\server1.txt" /D /E /R /I /K /Y 
del "C:\Users\Kratos\Desktop\MC Server\server.txt" 
echo Finished Log Split and Log Backup... 
goto time 
:sat1 
@echo %date% 
@echo %time% 
echo Starting the 12hr Log Split and Log Backup... 
ping 1.1.1.1 -n 1 -w 3000 >nul 
xcopy "C:\Users\Kratos\Desktop\MC Server\server.txt" "C:\Users\Kratos\Dropbox\Minecraft Backups\Logs\5-sat\server1.txt" /D /E /R /I /K /Y 
del "C:\Users\Kratos\Desktop\MC Server\server.txt" 
echo Finished Log Split and Log Backup... 
goto time 
:sun1 
@echo %date% 
@echo %time% 
echo Starting the 12hr Log Split and Log Backup... 
ping 1.1.1.1 -n 1 -w 3000 >nul 
xcopy "C:\Users\Kratos\Desktop\MC Server\server.txt" "C:\Users\Kratos\Dropbox\Minecraft Backups\Logs\6-sun\server1.txt" /D /E /R /I /K /Y 
del "C:\Users\Kratos\Desktop\MC Server\server.txt" 
echo Finished Log Split and Log Backup... 
goto time 
:mon2 
@echo %date% 
@echo %time% 
echo Starting the 12hr Log Split and Log Backup... 
ping 1.1.1.1 -n 1 -w 3000 >nul 
xcopy "C:\Users\Kratos\Desktop\MC Server\server.txt" "C:\Users\Kratos\Dropbox\Minecraft Backups\Logs\0-mon\server2.txt" /D /E /R /I /K /Y 
del "C:\Users\Kratos\Desktop\MC Server\server.txt" 
echo Finished Log Split and Log Backup... 
goto time 
:tue2 
@echo %date% 
@echo %time% 
echo Starting the 12hr Log Split and Log Backup... 
ping 1.1.1.1 -n 1 -w 3000 >nul 
xcopy "C:\Users\Kratos\Desktop\MC Server\server.txt" "C:\Users\Kratos\Dropbox\Minecraft Backups\Logs\1-tue\server2.txt" /D /E /R /I /K /Y 
del "C:\Users\Kratos\Desktop\MC Server\server.txt" 
echo Finished Log Split and Log Backup... 
goto time 
:wed2 
@echo %date% 
@echo %time% 
echo Starting the 12hr Log Split and Log Backup... 
ping 1.1.1.1 -n 1 -w 3000 >nul 
xcopy "C:\Users\Kratos\Desktop\MC Server\server.txt" "C:\Users\Kratos\Dropbox\Minecraft Backups\Logs\2-wed\server2.txt" /D /E /R /I /K /Y 
del "C:\Users\Kratos\Desktop\MC Server\server.txt" 
echo Finished Log Split and Log Backup... 
goto time 
:thu2 
@echo %date% 
@echo %time% 
echo Starting the 12hr Log Split and Log Backup... 
ping 1.1.1.1 -n 1 -w 3000 >nul 
xcopy "C:\Users\Kratos\Desktop\MC Server\server.txt" "C:\Users\Kratos\Dropbox\Minecraft Backups\Logs\3-thu\server2.txt" /D /E /R /I /K /Y 
del "C:\Users\Kratos\Desktop\MC Server\server.txt" 
echo Finished Log Split and Log Backup... 
goto time 
:fri2 
@echo %date% 
@echo %time% 
echo Starting the 12hr Log Split and Log Backup... 
ping 1.1.1.1 -n 1 -w 3000 >nul 
xcopy "C:\Users\Kratos\Desktop\MC Server\server.txt" "C:\Users\Kratos\Dropbox\Minecraft Backups\Logs\4-fri\server2.txt" /D /E /R /I /K /Y 
del "C:\Users\Kratos\Desktop\MC Server\server.txt" 
echo Finished Log Split and Log Backup... 
goto time 
:sat2 
@echo %date% 
@echo %time% 
echo Starting the 12hr Log Split and Log Backup... 
ping 1.1.1.1 -n 1 -w 3000 >nul 
xcopy "C:\Users\Kratos\Desktop\MC Server\server.txt" "C:\Users\Kratos\Dropbox\Minecraft Backups\Logs\5-sat\server2.txt" /D /E /R /I /K /Y 
del "C:\Users\Kratos\Desktop\MC Server\server.txt" 
echo Finished Log Split and Log Backup... 
goto time 
:sun2 
@echo %date% 
@echo %time% 
echo Starting the 12hr Log Split and Log Backup... 
ping 1.1.1.1 -n 1 -w 3000 >nul 
xcopy "C:\Users\Kratos\Desktop\MC Server\server.txt" "C:\Users\Kratos\Dropbox\Minecraft Backups\Logs\6-sun\server2.txt" /D /E /R /I /K /Y 
del "C:\Users\Kratos\Desktop\MC Server\server.txt" 
echo Finished Log Split and Log Backup... 
goto time 

이 코드 전체를 살펴본 사람 중 특히 감사합니다. 오류가있는 사람을 찾아 주셔서 감사합니다.

답변

0

위의 코드는 사용하기 전에 다음 tm 변수가 할당되지 않은 완전한 프로그램 인 경우. 제로 (

set tm=%time% 

:time 라벨 아래로 이동해야 ...

+0

고맙습니다. 참으로 나는 눈이 멀었다. 날짜 아래에'tm = % time %'세트가 있습니다. 다시 작성하고 시간 섹션과 날짜 섹션을 전환 했으므로 오류가 발생 했어야합니다. 새로운 눈으로 내 문제를 해결할 수 있습니다. –

+0

전체 ** 피연산자 없음 ** 오류가 수정되었지만 지금은 시간이 지났을 때 명령을 실행 한 후 초가 창 외부에 도달하면 다른 피연산자 ** 오류가 발생하는 것처럼 보입니다. ': I이 줄 좁혀 minutes1 를/F "토큰 = 1 * delims = 0"에 대한 %% A의 ("$ 0 % mm의 %") 설정 하는가/A MM = %% B 경우 % MM % EQU 0 고토 초 1 고토 hour2' 는 IT가 설정되지 않은 기록에 따르면 (내가 게시 된 코드가 코딩하는 방법을 모르는 사람들을 위해 작동하지 만들었 기 때문에 서로 다른, 그래서 그들은 그것을 훔칠 수 없습니다)이 ** MM ** ** ** % mm % ** ** MM **이 설정되지 않았기 때문에 오류가 발생합니다. –

+0

이 새로운 오류에 대한 질문은 [Link] (http://stackoverflow.com/questions/17621363/batch-during-my-code-loop-it-stops-setting-a-variable-all-help)에서 확인할 수 있습니다. -환영). 오류에 대한 자세한 정보를 제공합니다. –

-1

글쎄, 당신은 디버그를 사용하여 오류를 볼 수 있습니다. 다음과 같이하십시오 :

> bash -x script1.sh 

자세한 내용은 다음 URL을보고하십시오.

http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_02_03.html

+0

나는 배치 파일이 될 것 같지 않기 때문에이 데프 쓸모가 그 bash는 사물의 모양에서 배치 파일 ;-) – Aacini

+0

을 디버깅 할 수 있다고 생각하지 않습니다. –

0

본질적으로이 코드가 반복되는 코드를 대체하고, 또한 강력한 시간과 날짜 변수 세트를 제공한다 :이 라인이 있다고 생각 덧붙여서 Wmic (XP Pro 이상)를 사용합니다.

이는 XCOPY 루틴의 변수 %var%%server%를 사용합니다.

:scheduletimes%hh%이라는 변수를 설정하고 다시 설정하는 것처럼 보이며 동일한 변수를 반복해서 테스트하므로 루틴이 이상하게 보입니다. 당신이 너무 단순화 할 수 있습니다 후 일정 시간에 대한 정보를 제공하는 경우

.

@echo off 

title Log Split And Backup 

rem wd = week day 
rem mh = month 
rem dy = day 
rem yr = year 
rem hh = hour 
rem mm = minute 
rem ss = second 
rem ms = milisecond 
rem gtr = greater than 
rem lss = less than 
rem equ = equal to 

echo Starting Log Split And Backup... 
ping -n 1 localhost >nul 
cls 
echo Log Split And Backup Has Started... 

:time 
for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find "."') do set dt=%%a 
set Yr=%dt:~0,4% 
set Mh=%dt:~4,2% 
set Dy=%dt:~6,2% 
set HH=%dt:~8,2% 
set MM=%dt:~10,2% 
set SS=%dt:~12,2% 
set MS=%dt:~15,2% 

:date 
set dt=%date% 
set wd=%dt:~0,3% 


:scheduletimes 
:hour1 
for /f "tokens=1*delims=0" %%a in ("$0%hh%") do set /a HH=%%b 
if %HH% equ 6 goto minutes1 
goto hour2 
:minutes1 
for /f "tokens=1*delims=0" %%a in ("$0%hh%") do set /a HH=%%b 
if %HH% equ 0 goto seconds1 
goto hour2 
:seconds1 
for /f "tokens=1*delims=0" %%a in ("$0%hh%") do set /a HH=%%b 
if %HH% lss 10 set server=server1 
goto hour2 
:hour2 
for /f "tokens=1*delims=0" %%a in ("$0%hh%") do set /a HH=%%b 
if %HH% equ 18 goto minutes2 
goto time 
:minutes2 
for /f "tokens=1*delims=0" %%a in ("$0%hh%") do set /a HH=%%b 
if %HH% equ 0 goto seconds2 
goto time 
:seconds2 
for /f "tokens=1*delims=0" %%a in ("$0%hh%") do set /a HH=%%b 
if %HH% lss 10 set server=server2 

    if "%wd%"=="MON" set var=0-%wd% 
    if "%wd%"=="TUE" set var=1-%wd% 
    if "%wd%"=="WED" set var=2-%wd% 
    if "%wd%"=="THU" set var=3-%wd% 
    if "%wd%"=="FRI" set var=4-%wd% 
    if "%wd%"=="SAT" set var=5-%wd% 
    if "%wd%"=="SUN" set var=6-%wd% 

:logsplitting 

echo %date% 
echo %time% 
echo Starting the 12hr Log Split and Log Backup... 
ping -n 1 localhost >nul 
xcopy "C:\Users\Kratos\Desktop\MC Server\server.txt" "C:\Users\Kratos\Dropbox\Minecraft Backups\Logs\%var%\%server%.txt" /D /E /R /I /K /Y    
del "C:\Users\Kratos\Desktop\MC Server\server.txt" 
echo Finished Log Split and Log Backup... 
goto time