Search code examples
batch-filecommanddostimedoperand

Batch: I need some fresh eyes to see where the error is


I keep getting a Missing operand error. I cant seem to find it and I figure a new set of eyes can.

@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

Thank you to anyone that looked through this entire code and especially thank you to the person that finds the error for me.


Solution

  • If the above code is your complete program, then tm variable has not been assigned before it is used. I think that this line:

    set tm=%time%
    

    needs to be moved below :time label...