Need help with coding

 
Thread Tools Search this Thread
Special Forums Windows & DOS: Issues & Discussions Need help with coding
# 1  
Old 03-26-2012
Error Need help with coding

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.

below is the source code(.dat)

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


Last edited by Corona688; 03-26-2012 at 07:26 PM..
# 2  
Old 03-26-2012
Bumping up posts or double posting is not permitted in these forums.

Please read the rules, which you agreed to when you registered, if you have not already done so.

You may receive an infraction for this. If so, don't worry, just try to follow the rules more carefully. The infraction will expire in the near future

Thank You.

The UNIX and Linux Forums.
# 3  
Old 03-26-2012
Quote:
Originally Posted by Corona688
Bumping up posts or double posting is not permitted in these forums.

Please read the rules, which you agreed to when you registered, if you have not already done so.

You may receive an infraction for this. If so, don't worry, just try to follow the rules more carefully. The infraction will expire in the near future

Thank You.

The UNIX and Linux Forums.
sorry.. thanks for reminding me.
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

HTTP coding

My company has an in house instant messaging system (like WhatsApp) where users can communicate with each other. I currently have code to email me certain items from my Sparc machine running SunOS 5.10. I want what I am emailing myself to now instant message me. The team that created the messenger... (5 Replies)
Discussion started by: shorty
5 Replies

2. Shell Programming and Scripting

Need help with coding

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. ... (1 Reply)
Discussion started by: crazydude80
1 Replies

3. AIX

need help for coding this logic

contact me on <email address deleted> or <email address deleted> (1 Reply)
Discussion started by: suprithhr
1 Replies

4. UNIX for Dummies Questions & Answers

pro*c coding

Hi All, I am new to pro*C. I have a select statement as select a.ename,a.sal,a.empno from emp where &n=(select count(distinct(b.sal)) from emp b where a.sal<=b.sal for this query I have to write a pro*C program. So can you please send me the complete code. Then I will foloow the same... (1 Reply)
Discussion started by: user71408
1 Replies

5. Shell Programming and Scripting

Coding on my Mac

I would like to start coding on my mac, but I'm getting an error when I attempt to execute my script -bash : testscript: command not found I have verified that the #! line points to the correct directory. If you have some insight it would be greatly appreciated! - D (1 Reply)
Discussion started by: DKNUCKLES
1 Replies

6. UNIX for Advanced & Expert Users

can I use this coding

I apologise because I had pasted this question in the newbies forum first (because i am a bit of a newbie) but thought it might be better suited in here if i have to sepearate parameters can I use this syntax especially the or part (||) and is this correct if (6 Replies)
Discussion started by: w33man
6 Replies
Login or Register to Ask a Question