Thread: Need help with coding

  1. #1
    Registered User
    Join Date
    Mar 2012
    Posts
    6

    Lightbulb 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.


    --------------------------------------------------------------------------------------
    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

  2. #2
    Registered User
    Join Date
    Mar 2012
    Posts
    6
    any 1 to help me ..

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Why don't you begin with posting this in an appropriate forum/board?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Registered User
    Join Date
    Mar 2012
    Posts
    6
    Quote Originally Posted by Elysia View Post
    Why don't you begin with posting this in an appropriate forum/board?
    sorry.. where should i post it then ? thanks

  5. #5
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    It is curious that I mentioned the other day about support for Scripting, but proper scripting languages really, , however at the present time this is not offered on these pages, the name is CBoard, so it is C family languages you will get help with here strictly speaking. You have postd on the wrong forum
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  6. #6
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    sorry.. where should i post it then ? thanks
    Thats for you to find out mate.

    You managed to write a rather lengthy list of commands likethat and have been writing like that for a while one would assume, and you have never before tried to source help / examples for your chosen writing?? Is it just a copy paste thing you found then?
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  7. #7
    Registered User
    Join Date
    Mar 2012
    Posts
    6
    Quote Originally Posted by rogster001 View Post
    Thats for you to find out mate.

    You managed to write a rather lengthy list of commands likethat and have been writing like that for a while one would assume, and you have never before tried to source help / examples for your chosen writing?? Is it just a copy paste thing you found then?
    Hi sorry,
    This code is written my ex buddy who just left the company. My boss all of sudden ask me to take over the responsibility but i dont have much experience in scripting.
    That's why im seeking pro's help. Much appreciated in can guide me.

    thanks

  8. #8
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Well, like we said... this is a programming forum for C and C++, basically. That is where our expertise lies.
    We strongly recommend that you try forums that specialize in scripting in order to maximize the responses you get.
    Otherwise you'd post this in the Techboard, because this has nothing to do with C++.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #9
    Registered User
    Join Date
    Mar 2012
    Posts
    6
    Quote Originally Posted by Elysia View Post
    Well, like we said... this is a programming forum for C and C++, basically. That is where our expertise lies.
    We strongly recommend that you try forums that specialize in scripting in order to maximize the responses you get.
    Otherwise you'd post this in the Techboard, because this has nothing to do with C++.
    ok. sorry for the trouble as im new to this. thanks for the advice.

  10. #10
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    My boss all of sudden ask me to take over the responsibility
    Clever management there then!

    Didnt your colleague document the work?

    Anyway, as said, one of mods may move this to tech board and see if anything comes up, I know some scripting but not like your example.
    Last edited by rogster001; 03-26-2012 at 02:55 PM.
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  11. #11
    Registered User
    Join Date
    Mar 2012
    Posts
    6
    Quote Originally Posted by rogster001 View Post
    Clever management there then!

    Didnt your colleague document the work?

    nope. the problem is im newly appointed. no chance to work with him as i met him less than a week before he resigned. thats y im stuck here..

  12. #12
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    Yes but if he was writing stuff then it should have been documented, if not, crazy way to work
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  13. #13
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Moved to tech board (for what good it will do) and code tagged (for what good it will do).
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How coding -WHILE
    By hakimstm1b in forum C Programming
    Replies: 19
    Last Post: 10-16-2010, 07:51 AM
  2. C++ coding help
    By abhay143 in forum C++ Programming
    Replies: 1
    Last Post: 10-20-2009, 10:07 AM
  3. you know you've been coding too much when...
    By orion- in forum C++ Programming
    Replies: 5
    Last Post: 09-05-2005, 03:57 PM
  4. coding.
    By programer9000 in forum C++ Programming
    Replies: 2
    Last Post: 01-30-2003, 08:59 PM
  5. coding with dev-cpp
    By gamer in forum C++ Programming
    Replies: 2
    Last Post: 01-25-2003, 02:09 AM