Loading ...
Sorry, an error occurred while loading the content.
 

Re: [BATCH WORLD] logs for ftp script

Expand Messages
  • foxidrive
    ... As habs3 has mentioned, and particularly with the logging, you will have to play a large role in creating the statements for the log. ... This can be
    Message 1 of 8 , Nov 30, 2010
      On 1/12/2010 06:33, Abhijat Singh wrote:
      >
      > Hi Group, I have some scheduled dos batch scripts. I would like to
      > generate logs for them at some specific directory (say, C:\logs) such
      > that:

      As habs3 has mentioned, and particularly with the logging, you will have
      to play a large role in creating the statements for the log.

      > 1. The log file should have name as<batch_file_name>_<yyyymmdd>.log

      This can be achieved using the script for yyyymmdd_hhmms and the batch
      file name can be found from %~nx0 and the following is a general method
      of creating the log entry:

      echo log description here >> "%~nx0_%timestamp%.log"

      where %timestamp% is created from the script for yyyymmdd_hhmms


      One caveat: where the SHIFT keyword is used then the %~nx0 has to be
      saved into a variable before SHIFT is used. See below for a way of
      doing that.


      > 2. If the script runs n times in a day, the log file should have all
      > the n runs recorded, appended one below the other.
      >
      > I mostly do ftp and copy using these scripts, so, the log file should
      > be able to tell me if the file was downloaded/copied or not.

      You will have to use errorlevel values to see if commands have completed
      successfully, and commands like this to see if a file has copied.

      At the top of each batch file enter this to set the %timestamp% and the
      log filename:

      call c:\bat\timestamp.bat
      set log="c:\logs\%~nx0_%timestamp%.log"

      and then your log statements can use %log% like the following:
      In this case if the file does exist the the first echo statement will be
      used, otherwise the second echo statement will be used

      if exist filename.dat (
      echo pass and info into log file >> %log%
      ) else (
      echo fail and more info into log file >> %log%
      )
    • Abhijat Singh
      Hi Group/Foxidrive/Habs3! Sorry, I could not reply earlier. After taking the inputs from Foxidrive, I tried this: call C: BATCH Practice timestamp.bat set
      Message 2 of 8 , Dec 7, 2010
        Hi Group/Foxidrive/Habs3!

        Sorry, I could not reply earlier.
        After taking the inputs from Foxidrive, I tried this:

        call C:\BATCH\Practice\timestamp.bat
        set log="c:\Batch\Practice\logs\%~nx0_%timestamp%.log"
        if exist file1.txt (
        echo pass >> %log%
        echo ---------- >> %log%
        ) else (
        echo fail >> %log%
        echo ---------- >> %log%
        )

        the advantage this has over the script I was using earlier (mentioned below) is that I do not have to specify the file name any more. The disadvantage is that the log file name for the bat file script1.bat is something like script1.bat_20101207_1744.log. I would typically like to the file name to be script1_20101207_1744.log.

        Is there a standard way of achieving that?

        Once this is sorted, I will post my script on the errorlevel for your checking and help.

        Thanks very much!

        Kind Regards,
        Abhijat


        --- In batchworld@yahoogroups.com, "Abhijat Singh" <mail_abhijat@...> wrote:
        >
        > Hi there!
        > Here is the script I found.
        > The question I have is how to catch the system generated errors.
        >
        > :: 20100927 - This script copies the security master data from <source_path> to <dest_path>
        >
        > @ECHO OFF
        > ::thanks to foxidrive and batchworld@yahoogroups.com
        >
        > ::previous working date
        > set d=0
        >
        > :loop
        > set /a d=d-1
        > echo >%temp%.\tmp.vbs y = DateAdd("d",%d%,now)
        > echo>>%temp%.\tmp.vbs dow = WeekDayName(Weekday(y),1)
        > echo>>%temp%.\tmp.vbs m = CStr(Month(y))
        > echo>>%temp%.\tmp.vbs m = CStr(Right("0"+m,2))
        > echo>>%temp%.\tmp.vbs d = CStr(Day(y))
        > echo>>%temp%.\tmp.vbs d = CStr(Right("0"+d,2))
        > echo>>%temp%.\tmp.vbs y = CStr(Year(y))
        > echo>>%temp%.\tmp.vbs WScript.Echo "set WRKDATE="+y+m+d
        > echo>>%temp%.\tmp.vbs WScript.Echo "set dow="+dow
        > cscript //nologo %temp%.\tmp.vbs > %temp%.\tmp.bat
        >
        >
        > call %temp%.\tmp.bat
        > del %temp%.\tmp.bat
        >
        > if /i "%dow%"=="Sun" goto :loop
        > if /i "%dow%"=="Sat" goto :loop
        >
        > ::today's date
        > for /f "tokens=2,3,4 delims=/ " %%a in ('date /t') do set LOGDATE=%%c%%a%%b
        >
        > if exist <Log_Path>\IB_Security_Master_%LOGDATE%.log (goto :update_log)
        >
        > :create_log
        > copy nul <Log_Path>\IB_Security_Master_%LOGDATE%.log
        >
        > :update_log
        > echo %date% %time% >> <Log_Path>\IB_Security_Master_%LOGDATE%.log
        > echo Script working for date = %WRKDATE% >> <Log_Path>\IB_Security_Master_%LOGDATE%.log
        >
        > copy <Source_Path>\world_%WRKDATE%_london_master.tsv <Dest_Path>\.
        >
        > if exist <Dest_Path>\world_%WRKDATE%_london_master.tsv (goto :success_log) else (goto :failure_log)
        >
        > :success_log
        > echo copy success! >> <Log_Path>\IB_Security_Master_%LOGDATE%.log
        > goto :end
        >
        >
        > :failure_log
        > echo copy failure! >> <Log_Path>\IB_Security_Master_%LOGDATE%.log
        >
        > :end
        > echo ---------------------- end of log ---------------------- >> <Log_Path>\IB_Security_Master_%LOGDATE%.log
        >
        > One another thing that was on my mind was how do I catch the errors when I download a series of files via ftp, but I guess I will take it up once this is done.
        >
        > Thanks very much!
        >
        > Kind Regards,
        > Abhijat.
        >
        >
        > --- In batchworld@yahoogroups.com, habs3 <habs3@> wrote:
        > >
        > > Excellent. This will allow us all to look at the script and either answer with a
        > > solution or at least learn from others knowledge. Thanks again.
        > >
        > >
        > >
        > >
        > >
        > > ________________________________
        > > From: Abhijat Singh <mail_abhijat@>
        > > To: batchworld@yahoogroups.com
        > > Sent: Tue, November 30, 2010 3:26:06 PM
        > > Subject: Re: [BATCH WORLD] logs for ftp script
        > >
        > >
        > > Hi there,
        > > I share the same feeling. Thanks for the heads up!
        > > I had work on the log file concept before, but I guess, wasn't able to catch the
        > > error well.
        > > I will dig out my script and ask more specific questions, not only for this but
        > > also for the future posts.
        > >
        > > Kind Regards,
        > > Abhijat.
        > >
        > > --- In batchworld@yahoogroups.com, habs3 <habs3@> wrote:
        > > >
        > > > Hi Abhijat
        > > >
        > > > Speaking for myself this is a user group where if we have a problem with a
        > > > script and stuck we can assist and learn accordingly. You continue to ask for
        > > > scripts to be created for you to complete your tasks. I do not believe this is
        > > >a
        > > >
        > > > script request site but a site to assist with getting over a hurdle that is
        > > > stopping a script YOU created from working properly. If you need a script use
        > > > Google to find the script alter it for yourself and if you need assistance
        > > > please post your question. Remember to give credit from the person or persons
        > > > you took the script from originally.
        > > >
        > > > Thank You.
        > > >
        > > >
        > > >
        > > >
        > > >
        > > > ________________________________
        > > > From: Abhijat Singh <mail_abhijat@>
        > > > To: batchworld@yahoogroups.com
        > > > Sent: Tue, November 30, 2010 2:33:59 PM
        > > > Subject: [BATCH WORLD] logs for ftp script
        > > >
        > > >
        > > >
        > > > Hi Group,
        > > > I have some scheduled dos batch scripts. I would like to generate logs for them
        > > >
        > > > at some specific directory (say, C:\logs) such that:
        > > >
        > > > 1. The log file should have name as <batch_file_name>_<yyyymmdd>.log
        > > > 2. If the script runs n times in a day, the log file should have all the n runs
        > > >
        > > > recorded, appended one below the other.
        > > >
        > > >
        > > > I mostly do ftp and copy using these scripts, so, the log file should be able
        > > >to
        > > >
        > > > tell me if the file was downloaded/copied or not.
        > > >
        > > >
        > > > This measure is taken mainly because the scripts run during non-business hours,
        > > >
        > > > and if something goes wrong, I should be able to figure it out by looking at
        > > >the
        > > >
        > > > log file.
        > > >
        > > > Hope I am not too much of trouble on you.
        > > >
        > > > Thanks very much!
        > > >
        > > > Kind Regards,
        > > > Abhijat.
        > > >
        > > >
        > > >
        > > >
        > > >
        > > >
        > > >
        > > > [Non-text portions of this message have been removed]
        > > >
        > >
        > >
        > >
        > >
        > >
        > >
        > >
        > > [Non-text portions of this message have been removed]
        > >
        >
      • foxidrive
        ... change %~nx0 to %~n0 The n gives it the filename and the x adds the extension.
        Message 3 of 8 , Dec 7, 2010
          On 8/12/2010 09:57, Abhijat Singh wrote:

          > After taking the inputs from Foxidrive, I tried this:
          >
          > call C:\BATCH\Practice\timestamp.bat
          > set log="c:\Batch\Practice\logs\%~nx0_%timestamp%.log"
          > if exist file1.txt (
          > echo pass>> %log%
          > echo ---------->> %log%
          > ) else (
          > echo fail>> %log%
          > echo ---------->> %log%
          > )
          >
          > the advantage this has over the script I was using earlier (mentioned below) is that I do not have to specify the file name any more. The disadvantage is that the log file name for the bat file script1.bat is something like script1.bat_20101207_1744.log. I would typically like to the file name to be script1_20101207_1744.log.
          >
          > Is there a standard way of achieving that?


          change %~nx0 to %~n0

          The n gives it the filename and the x adds the extension.
        Your message has been successfully submitted and would be delivered to recipients shortly.