4 Replies Latest reply on Feb 26, 2020 5:44 PM by Kai Nicholson

    file watcher %%$ODATE

    davide aliperti
      Share This:

      Hi guys,

      I'm trying to put in place a file watcher job that detectes file with order date in the name


      This is the script I prepared :


      ON_FILEWATCH /applications/data/transfer/BANCLL74_%%$ODATE*.OK CREATE


      DO_CMD ctmvar -action set -var "%%\BANCLL74" -varexpr %FILENAME%



      and this is the file:

      [pwcdlit1@fraitdbox01668 transfer]$ pwd


      [pwcdlit1@fraitdbox01668 transfer]$ ls -ltr *74*

      -rw-r--r--. 1 pwcdlit1 itpwclake 0 Feb 24 14:01 BANCLL74_20200224.OK


      I also displayed the content of the variable %%$ODATE and it is 20200224, but the job never finishes, it is always in executing....


      Any suggestion?




        • 1. Re: file watcher %%$ODATE
          Haw Kor



          In your rule file you have specified the following:

          ON_FILEWATCH /applications/data/transfer/BANCLL74_%%$ODATE*.OK CREATE



          The options for this are:

          ON_FILEWATCH <fileName>(absolute path) [CREATE/DELETE] [min_size] [min_detect] [wait_time]
          [start_time] [cyclic_interval] [wildcards] [minimal_file_age]


          You have not specified a wait_time so that would default to a value of 0 meaning there is no time limit to wait:



          Maximum time (in minutes) to run the process without detecting the file at its minimum size (CREATE) or detecting its deletion (DELETE). If the file is not detected/deleted in this specified time frame, the process terminates with an error return code, as described in ctmfw- return codes table below.. Default: 0 (no time limit).


          Maybe you can try adding two additional lines like:

          INTERVAL 10

          WAIT_TIME 1

          ON_FILEWATCH /applications/data/transfer/BANCLL74_%%$ODATE*..OK CREATE

          2 of 2 people found this helpful
          • 2. Re: file watcher %%$ODATE
            Mun Keong Lee

            Hi Davide

            Control-M variables like %%$ODATE can only be used within a job definition. The rule file is an external file which cannot resolve Control-M variables. My suggestion is to create a "normal" file watcher job and make use of "Capture from job output" to get the filename. One possible solution is in a post that I have replied to Looking for suggestions on the following use case . In my example, I'm capturing the value into a Smart folder variable. In your case, it should be global variable or whatever variable type that is in the scope of the other job that requires it. The value of Path should be "/applications/data/transfer/BANCLL74_%%$ODATE*.OK". It's important to enclose the path in "". After job has been ordered, view the job output to confirm that the filewatcher is watching for the correct file.




            • 3. Re: file watcher %%$ODATE
              Karl Fiedler

              Hi Davide,


              sometimes it works work, but anyway the correct spec. in  the Job is as follows:


              %%$ODATE..OK or depends on your request %%$ODATE.*.OK


              You have to add one dot as delimiter for the autoedit and another one that is part of the filename themselve.


              best regards



              • 4. Re: file watcher %%$ODATE
                Kai Nicholson

                Hi Davide..


                I had a similar issue a while ago - as Mun Keong Lee noted, variables don't work in filewatcher scripts..

                In my case, I needed to use a filewatcher script (filewatcher job type/form, or instream AFT/MFT filewatcher wouldn't do what I needed), so I got around it by adding an additional job with PARM1 = %%$ODATE that created the filewatcher script - including the value of %%$ODATE rather than variable name - immediately before the actual job, then using the newly created filewatcher script as the input script for the filewatcher.


                A slightly modified version of the script that I put together is below (hope it's readable - I can't see a way here to format a code block).  There may be a more elegant way to do it, but it worked for me and did what I needed, although it was quite a few years ago that I wrote it, so no guarantees..



                ---> Start script



                # $1 = PARM1 %%$ODATE



                # Delete file if it exists

                if [ -f $FW_INPUT_SCRIPT ];


                   echo "File exists - deleting"

                   rm $FW_INPUT_SCRIPT



                # Create filewatcher input file.

                # Required as FW input files can't contain variables.


                echo \# This is a ControlM File Watcher job, and created AS NEEDED > $FW_INPUT_SCRIPT

                echo \# Filewatcher for xxxx  >> $FW_INPUT_SCRIPT

                echo \# ------------------------------------------------------------------ >> $FW_INPUT_SCRIPT

                echo \# Mandatory Parameters >> $FW_INPUT_SCRIPT

                echo INTERVAL 1 \# Sleep interval \(seconds\) >> $FW_INPUT_SCRIPT

                echo FROM_TIME 0000 \# Starting time for all files \(hhmm\) >> $FW_INPUT_SCRIPT

                echo MIN_SIZE 0 \# Minimum size for all files \(bytes\) >> $FW_INPUT_SCRIPT

                echo MIN_DETECT 5 \# Number of iterations for all files >> $FW_INPUT_SCRIPT

                echo WAIT_TIME 180 \# Time limit for all files \(minutes\) >> $FW_INPUT_SCRIPT


                echo \#  ON_FILEWATCH statements >> $FW_INPUT_SCRIPT





                echo THEN >> $FW_INPUT_SCRIPT

                echo DO_OK >> $FW_INPUT_SCRIPT

                echo ELSE >> $FW_INPUT_SCRIPT

                echo DO_NOTOK >> $FW_INPUT_SCRIPT

                echo END_ON >> $FW_INPUT_SCRIPT



                ---> End script




                2 of 2 people found this helpful