HI,
Can some one guide me how to make changes to the script below so that it can load the history of a program to IT server ?
Format of data:
YYYYMMDD065959.dsk.log
YYYYMMDD235959.dsk.log
currently both are loaded together. Need to separate them as above format.
Thanks in advance.
--------------------------------------------------------------------------------------
Code://My source_code
::Set Enable Extensions for If function
@setlocal ENABLEEXTENSIONS
::Set Version of the script
@set CurVer=Version 1.00 2012-03-07
::Temporary get date just for log file
@for /f "tokens=2-4 delims=-./ " %%l in ('echo %date%') do @(
set tempmon=%%l
set tempday=%%m
set tempyear=%%n
)
::Set history log file name
@set HistFile=%tempyear%%tempmon%his.txt
::Add empty line to history log file
@echo.>> %HistFile%
::Start the script
@echo %date% - %time% : Seq1000: Start Script %CurVer%>> %HistFile%
::----------------------------------------------------------------------
::Local variables
::End of date time
@set end_time=235959
::Morning time
@set mor_time=065959
::Source Directory where original data is stored (default: C:\MAP\LOG)
@set src_dir=C:\MAP\LOG
::Working Directory where data will be kept and sent to server
@set wrk_dir=C:\Ftp2It
::Yesterday text file contain yesterday date
@set yes_name=yesterday.src
::Name of File containing history data
@set DataName=mc01.log
::Ftp target
@set ftp_tar=10.81.155.178
::Ftp command
@set ftpcmd=ftp_cmd.src
::Delay time by second:
@set DLayTime=300
::----------------------------------------------------------------------
::Properly get current date from the system
::StartString where the start of Date String
::1 if there is no day of week at beginning
::2 if there is day of week at beginning
@set StartString=1
::Check if 1st character of date string is Numeric or not (compare 1st character >= "A")
@if "%date:~0,1%" GEQ "A" (set StartString=2)
::Print StartString to check
@echo %date% - %time% : Seq1010: StartString=%StartString% >> %HistFile%
::get the current date format
::assign current month to mm, day to dd, year to yy
@for /f "tokens=2-4 delims=(-)" %%a in ('echo/^|date') do @(
@for /f "tokens=%StartString%-4 delims=-./ " %%x in ('echo %date%') do @(
set %%a=%%x
set %%b=%%y
set %%c=%%z
)
)
::Check if return year if less than 50 then change to 20xx
@set yyyy=%yy%
@if %yy% LSS 50 (set yyyy=20%yy%)
@set MyToday=%yyyy%%mm%%dd%
@echo %date% - %time% : Seq1020: MyToday=%MyToday% >> %HistFile%
::Delay to prevent could not connect to FTP after Logon
::Move to new Seq 1185
::@echo Delay for %DLayTime% secs, Please wait.....
::@echo %date% - %time% : Seq1025: Delay for %DLayTime% secs, Please wait..... >> %HistFile%
::@ping 127.0.0.1 -n %DLayTime% >NUL
::----------------------------------------------------------------------
::set current hour and compare current hour to decide which function
@set /A cur_Hour=%time:~0,2%
@echo %date% - %time% : Seq1030: cur_Hour=%cur_Hour% >> %HistFile%
@echo %date% - %time% : Seq1040: if %cur_Hour% LSS 23 (goto Bef_23) >> %HistFile%
@if %cur_Hour% LSS 23 (goto Bef_23)
@goto Aft_23
::----------------------------------------------------------------------
::Before 23 O'clock
::Send Yesterday data and Today data
:Bef_23
@echo %date% - %time% : Seq1050: Routine Bef_23 >> %HistFile%
::Check if yesterday.src not exist, no need to get yesterday data
@echo %date% - %time% : Seq1060: if not exist %wrk_dir%\%yes_name% goto NextStep1 >> %HistFile%
@if not exist %wrk_dir%\%yes_name% goto NextStep1
::get yesterday date inside text file
@for /f "tokens=1-2 delims= " %%f in ('type %wrk_dir%\%yes_name%') do (
@set YestData=%%f
)
@echo %date% - %time% : Seq1070: YestData=%YestData% >> %HistFile%
::Copy yesterday history data to working folder
@echo %date% - %time% : Seq1080: if not exist %src_dir%\%YestData%%end_time%.%DataName% (goto NextStep1) >> %HistFile%
@if not exist %src_dir%\%YestData%%end_time%.%DataName% (goto NextStep1)
@echo %date% - %time% : Seq1090: copy %src_dir%\%YestData%%end_time%.%DataName% %wrk_dir%\ /Y >> %HistFile%
@copy %src_dir%\%YestData%%end_time%.%DataName% %wrk_dir%\ /Y
:NextStep1
@echo %date% - %time% : Seq1100: Routine NextStep1 >> %HistFile%
::Copy today history data to working folder and rename to morning time
@echo %date% - %time% : Seq1110: if not exist %src_dir%\%MyToday%%end_time%.%DataName% (goto SendData) >> %HistFile%
@if not exist %src_dir%\%MyToday%%end_time%.%DataName% (goto SendData)
@echo %date% - %time% : Seq1120: copy %src_dir%\%MyToday%%end_time%.%DataName% %wrk_dir%\%MyToday%%mor_time%.%DataName% /Y >> %HistFile%
@copy %src_dir%\%MyToday%%end_time%.%DataName% %wrk_dir%\%MyToday%%mor_time%.%DataName% /Y
@goto SendData
::----------------------------------------------------------------------
::After 23 O-clock
::Send Today data and set yesterday date to some Text file
:Aft_23
@echo %date% - %time% : Seq1130: Routine Aft_23 >> %HistFile%
::If yesterday.src exist delete the file
@echo %date% - %time% : Seq1140: if exist %wrk_dir%\%yes_name% del %wrk_dir%\%yes_name% /Q >> %HistFile%
@if exist %wrk_dir%\%yes_name% del %wrk_dir%\%yes_name% /Q
::Write to yesterday.src for next day data sending.
@echo %date% - %time% : Seq1150: %MyToday% to %wrk_dir%\%yes_name% >> %HistFile%
@echo %MyToday%>>%wrk_dir%\%yes_name%
::Copy today history data to working folder
@echo %date% - %time% : Seq1160: if not exist %src_dir%\%MyToday%%end_time%.%DataName% (goto SendData) >> %HistFile%
@if not exist %src_dir%\%MyToday%%end_time%.%DataName% (goto SendData)
@echo %date% - %time% : Seq1170: copy %src_dir%\%MyToday%%end_time%.%DataName% %wrk_dir%\ /Y >> %HistFile%
@copy %src_dir%\%MyToday%%end_time%.%DataName% %wrk_dir%\ /Y
@goto SendData
::----------------------------------------------------------------------
::Sending data to ftp
:SendData
@echo %date% - %time% : Seq1180: Routine SendData >> %HistFile%
::Delay to prevent could not connect to FTP after Logon
@echo Delay for %DLayTime% secs, Please wait and DO NOT Close the script.....
@echo %date% - %time% : Seq1185: Delay for %DLayTime% secs, Please wait and DO NOT Close the script..... >> %HistFile%
@ping 127.0.0.1 -n %DLayTime% >NUL
@echo %date% - %time% : Seq1190: ftp -s:%wrk_dir%\%ftpcmd% %ftp_tar% >> %HistFile%
@ftp -s:%wrk_dir%\%ftpcmd% %ftp_tar%
::Clear all old data
@echo %date% - %time% : Seq1200: del %wrk_dir%\*.%DataName% /Q >> %HistFile%
@del %wrk_dir%\*.%DataName% /Q
::----------------------------------------------------------------------
::End of program
:EOL
::End of script
@echo %date% - %time% : Seq9000: End Script >> %HistFile%
::Add empty line to history log file
@echo.>> %HistFile%
@endlocal