1 2 Previous Next 16 Replies Latest reply on Sep 10, 2015 3:29 AM by MunKeong Lee

    How to make a filewatch job in control-m

      Share:|

      Hi guys,

       

      I'd like to make a filewatch job to monitor a folder in unix if there coming *.csv file then move the file to another folder in that unix box.

      The job need run every 30 minus how to do that?

       

      Best regards.

        • 1. Re: How to make a filewatch job in control-m
          Prakash Bendrikar

          Hi Allen

          File Watcher.jpg

          File Watcher Attributes (Details):

          Defines the following attributes:

          • Path :Defines the path of the file to be detected. The file name can include wildcard character * to represent any number of characters (including no characters) or ? to represent any one character.

           

          • Mode :

          Determines whether to detect creation or deletion of a file as follows:

          1. Create: Detects creation of a file. File size is ignored if the filename parameter contains wildcards (unless the monitor file size when wildcard is used parameter is set to Y).
          2. Delete: Detects deletion of a file. When the ctmfw utility is run in this mode, it first checks for files that match the specified name. After a specified file is detected, the ctmfw utility checks at the specified interval for deletion of that file.

           

          • Owner :Identifies the user name with the authorization to execute the job. This parameter is used by the Control-M security mechanism.

           

          • Min detected size :Minimum file size in bytes. This parameter is ignored if the FILE parameter contains wildcards (unless the monitor file size when wildcard is used parameter is set to Y) or if the mode parameter is set to DELETE.

           

          • Interval between file searches :Interval between successive attempts to detect the existence/deletion of a file (in seconds).

           

          • Interval between filesize comparison iterations :Interval between attempts to monitor the size of a file after it is detected (in seconds). This parameter is ignored when using wildcards in FILE or when using DELETE mode.

           

          • Number of iterations :Number of attempts to monitor file size where the size remains static and greater than or equal to minimum detected size (indicating successful creation of the file). This parameter is ignored when using wildcards in FILE or when using DELETE mode.

           

          • Monitor file size and file age when wildcard is used :Indicates whether file size should be monitored if the filename contains wildcards. This parameter is ignored if the filename does not contain a wildcard.

           

          • Time limit for the process :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.

           

          • Starting time for detecting files :Indicates an absolute time at which the utility starts monitoring the file.

           

          • Absolute stop time :Indicates an absolute time at which the file is no longer watched.

           

          • Maximal file age :Indicates the maximum amount of time that can pass since the file you want to watch was last modified.

           

          • Minimal file age :Indicates the minimum amount of time that must have passed since the file you want to watch was last modified

           

          • Save :Defines the Save button to save the Job specific settings.

          For more information about the ctmfw utility, see ctmfw File Watcher utility.

           

          For running job in every 30 min make it as Cyclic :

           

          CyclicFW.jpg

          Once done with File watch use AFT job for File Transfer .

          This would be done with GUI

           

          For Linux if NO GUI is available :

          The syntax of the ctmfw utility is:

          ctmfw FILE (absolute path)

          < mode (CREATE|DELETE)> Default: CREATE

          < minimum detected size <number> [' '|Bytes(B)|Kilo(K)|Mega(M)|Giga(G)] >Default:0

          < interval between file search (seconds) > Default: 60sec

          < interval between filesize comparison iterations (seconds) > Default: 10sec

          < number of iterations while the size is static > Default: 3 iterations

          < time limit for the process (minutes).> Default: 0 (no time limit) Effective while the file does not exists or, the file size is static and the minimum size was not reached >

          < monitor file size , minimal and maximal age, when wildcard is used > Default: N

          < starting time for detecting files (HHMM or YYYYMMDDHHMM > Default: NOW

          < absolute stop time (HHMM or YYYYMMDDHHMM > Default: +0000 ( No stop time )

          < minimal age of file (modified time) format:xxxxYxxxxMxxxxDxxxxHxxxxMin > Default: NO_MIN_AGE

          < maximal age of file ( timestamp monitoring ) format:xxxxYxxxxMxxxxDxxxxHxxxxMin > Default: NO_MAX_AGE The parameters of the ctmfw utility are described in the following table.

           

          All parameters must be assigned a value, even if that value is zero. If only six values are specified, the default value for mon_size_wildcard is used. If five parameters are specified, default values for wait_time and mon_size_wildcard are used, and so forth. ctmfw /home/watchedfile.txt CREATE 100 10

          is resolved by using default values for mon_int, min_detect, wait_time, and mon_size_wildcard as follows:

          ctmfw /home/samplefile.txt CREATE 100 10 10 3 0 N

           

           

          Regards,

           

          Prakash B

          • 2. Re: How to make a filewatch job in control-m
            MunKeong Lee

            Hi Allen:

            The FileWatcher template will not be able to meet your requirement. You will need to execute the ctmfw utility directly instead of doing it through the template. ctmfw comes together with the Control-M agent. If you are using the agent's OS account to execute ctmfw, no further setup is required. If you are going to use another OS account to execute ctmfw, you will need to set up the following environment variables before executing ctmfw.

            -------------------------------

            CONTROLM=<agentHome>/ctm

            export CONTROLM

            PATH=$PATH:<agentHome>/ctm/exe:<agentHome>/ctm/scripts

            export PATH

            LD_LIBRARY_PATH=$LD_LIBRARY_PATH:<agentHome>/ctm/exe

            -------------------------------

            You will need to provide ctmfw with an input file. The following input file will watch for *.csv in /dir1 and once detected, it will move it to /dir2. For simplicity, I'm keeping all parameters as default and only change the WAIT_TIME to 30. This will cause ctmfw to timeout after 30 mins if no file is detected and it will execute the statement, DO_OK, in the ELSE block. Remove the ELSE block, if you wish the job to complete NOTOK in the event of timeout.

            -------------------------------

            WAIT_TIME 30

            ON_FILEWATCH /dir1/*.csv CREATE

            THEN

            DO_CMD mv %FILENAME% /dir2

            ELSE
            DO_OK
            END_ON

            -------------------------------

            Use the following command in your OS job:

            ctmfw -input <full path>/<input file name>

             

            If your csv files can arrive at any time throughout the day and there may be more that 1 csv file at any one time, you will need to make the job cyclic. I suggest you make the cyclic interval as short as possible e.g. 0 or 1 minute, so that it goes back and monitor for more csv file once execution is completed. The job can only detect 1 csv file for each execution.

             

            Regards,

            MK

            • 3. Re: How to make a filewatch job in control-m

              Hi MK,

               

              What's the WAIT_TIME 30 mean? Will the ctmfw thread hold 30 mins ? if make the job into cyclic job then will there be many threads of ctmfw?

              • 4. Re: How to make a filewatch job in control-m

                Hi Mk,

                 

                Aslo , I create the os job and execute get
                failed to locate CONTROLM from env variable and from /etc/BMCSoftware/CONTROL-M-Agent/CTMIOAAPI

                • 5. Re: How to make a filewatch job in control-m
                  MunKeong Lee

                  Hi Allen:

                  Please see my earlier reply. You will need to set up the following variables if you are going to use another OS account to execute ctmfw. The best way to set this up is to put it in the login profile. If the OS account is using sh/ksh as login shell, you need to update the .profile file in the home directory. As the error message implies, you are missing the CONTROLM environment variable.

                  -------------------------------

                  CONTROLM=<agentHome>/ctm

                  export CONTROLM

                  PATH=$PATH:<agentHome>/ctm/exe:<agentHome>/ctm/scripts

                  export PATH

                  LD_LIBRARY_PATH=$LD_LIBRARY_PATH:<agentHome>/ctm/exe

                  -------------------------------

                  Regards,

                  MK

                  • 6. Re: How to make a filewatch job in control-m

                    Hi MK,

                     

                    Got it.

                     

                    Also I create a filewatcher job and leave all other parameter as default just input the path to xxx/*.csv.  Then I get the sysout :/app/ctmagent/ctm/runtime/CMD.0004ntzc_00d[2]: ctmfw:  not found.  Is that still the environment variable problem ?

                    • 7. Re: How to make a filewatch job in control-m
                      MunKeong Lee

                      Hi Allen:

                      The mistake is in the BMC doc . I just copy and paste from the V9 Utilities Guide. Please change this:


                      PATH=$PATH:<agentHome>/ctm/exe:<agentHome>/ctm/scripts

                      to

                      PATH=$PATH:<agentHome>/ctm/exe:<agentHome>/ctm/exe


                      Regards,

                      MK



                      • 8. Re: How to make a filewatch job in control-m

                        Hi MK,

                         

                        NP, So What I get from the control-m filewatcher job sysout is still because of the environment variable problem ?

                        • 9. Re: How to make a filewatch job in control-m
                          MunKeong Lee

                          Hi Allen:

                          Yes, it's definitely the PATH environment. The error is saying that it still can't find ctmfw after going through all directories specified in PATH.

                          If you are using bash as login shell (since you are using Linux), you have to update .bash_profile instead of .profile.

                          Regards,

                          MK

                          • 10. Re: How to make a filewatch job in control-m

                            Hi MK,

                             

                            I am use AIX, I think I'd like add below script into .profile of the control-m job owner account

                             

                             

                            CONTROLM=<agentHome>/ctm

                            export CONTROLM

                            PATH=$PATH:<agentHome>/ctm/exe

                            export PATH

                            LD_LIBRARY_PATH=$LD_LIBRARY_PATH:<agentHome>/ctm/exe

                            export LD_LIBRARY_PATH

                             

                            Is that right ?

                            • 11. Re: How to make a filewatch job in control-m
                              MunKeong Lee

                              Hi Allen:

                              Did you change <agentHome> to the actual agent directory? I use <agentHome> to represent the agent directory because I do not know where you will install the agent.

                              Once more thing - .profile is for sh/ksh login shell. Is your login shell correct? If it's csh, it will not work.

                              Regards,

                              MK

                              • 12. Re: How to make a filewatch job in control-m

                                Hi MK,

                                 

                                NP, Let me try first and give out the feedback.

                                • 13. Re: How to make a filewatch job in control-m

                                  Hi Mk,

                                   

                                  It's work now. BTW what's the mean of WAIT_TIME 30 ?

                                  • 14. Re: How to make a filewatch job in control-m
                                    MunKeong Lee

                                    Hi Allen:

                                    That's the maximum time in minutes that ctmfw will watch for *.csv files. If none are created within 30 minutes, ctmfw will end NOTOK but in my example, I force ctmfw to end OK. If you do not specify this parameter, it will wait forever for the file to be created and does not time out.   .

                                    Regards,

                                    MK

                                    1 2 Previous Next