13 Replies Latest reply on Feb 14, 2019 9:37 AM by Ram Iyer

    Getting a file via Control_m output upon ENDED OK ?

    Ram Iyer

      Getting a file via Control_m output upon ENDED OK ?

      =================================================

       

       

       

      Thanks for looking into my issues. I am using Control_m 9.0 on Linux. I did review control help, but I did not find an answer, so I am posting here.

       

      I am exploring a way to get output file created by the JOB executed/ENDED OK by Control M.

       

      We are runing a job using Control M. This JOB make a output file on linux server This is not a contolm server, but a control M agent is running on this server to handle control m requests.

       

      After JOB ENDED OK, we want to get that output file via control M.

       

      Are there any mechanism to do that ?

       

       

      Where can I find more info for resolutions?

       

       

       

      Thanks for guidance.

        • 1. Re: Getting a file via Control_m output upon ENDED OK ?
          Mark Francome

          Do you mean the sysout file from the job itself?

           

          If so you can use the Output Handling option -

          If you actually want another file then you can run any OS command in the Post-execution command field (from the General tab) although this will run regardless of if your job is ok or not.

           

          If you do want the file only if the main job is ok then you can run the job as a command and do the OS copy command after a '&&' -

           

          ./lib1/myscript.sh && copy output1.txt ....

          3 of 3 people found this helpful
          • 2. Re: Getting a file via Control_m output upon ENDED OK ?
            Juan Pablo Ojeda

            Hi Mark,  excellent suggestion!, the double & it's a neat trick, and also -for those who wonder- it works on Windows environment too.

             

            Also, wanted to share something regarding the previous suggestion, please consider that double ampersand will execute the command on the right if (and only if) the command on the left was executed successfully (return code 0). If the scripts fails during execution, and the exception / error is not handled by the script, it's possible that the copy command will never run.

             

            If said administrator wants to execute the copy, no matter what happens (regardless of the script competition status), then a single ampersand should be used, like the following example:

             

            ./lib1/myscript.sh & copy output1.txt ....          -- copy output will run always

             

            ./lib1/myscript.sh && copy output1.txt ...         -- copy output will run if myscript.sh ends successfully (usually that means, return code 0)

             

            Regards!

            2 of 2 people found this helpful
            • 3. Re: Getting a file via Control_m output upon ENDED OK ?
              Ram Iyer

              Thanks for your reply. I am facing another challenge of this testing part. Here is the scenario:

               

              1) We are calling a script, that make the file with file name pattern like outfile_<timestamp>

               

              2) I need to get this  outfile_<timestamp> to issue &&cp outfile_<timestamp>  after script run end

               

              How do I get this outfile_<timestamp> from script after it end ?

               

              I did review ctmvar, but it point to control m variable to script not other way around.

               

              What is the control M trick do this ?

               

              Thanks for sharing.

              • 4. Re: Getting a file via Control_m output upon ENDED OK ?
                Mark Francome

                Which version of Control-M do you have? You can capture output into variables in v9.

                • 5. Re: Getting a file via Control_m output upon ENDED OK ?
                  Ram Iyer

                  Thanks for your question/reply. It is interesting to know .

                   

                  How do we do that in V9?

                   

                  Thanks for sharing.

                   

                  I posted in my OP

                   

                  I am using Control_m 9.0 on Linux. I did review control help, but I did not find an answer, so I am posting here

                  .

                   

                  • 6. Re: Getting a file via Control_m output upon ENDED OK ?
                    Mark Francome

                    Sorry, I didn't see that.

                     

                    Out of the box, v9 has new functionality to do this. They have a simple YouTube video for this -

                     

                    Capture from Job Output and storing in Variables - YouTube

                     

                    If that isn't what you need then there are more scripted solutions, but I always think you're best off with the simple approach if possible.

                    • 7. Re: Getting a file via Control_m output upon ENDED OK ?
                      Ram Iyer

                      Thanks for your guidance. I am able to make this variable work.

                       

                      I got the filename after completion of JOB in %%OUTPUT_FILE

                       

                      I did && cp %%OUTPUT_FILE

                       

                      to resolve my OP raised issue.

                       

                      The file did not come along with Control M shout out attachment email notification. This attachment contain only run info and ECHO command, I placed to verify %%OUTPUT_FILE content .

                       

                      As per video

                       

                      I did ctmvar -ACTION LIST. It lists many variables/values, but I did not see %%OUTPUT_FILE as one of them

                       

                      How do I get the actual file via ENDED OK notification?

                       

                      Are there any additional steps to make this happen?

                       

                      I am getting

                       

                      cp: missing destination file operand after `file_0190211122426.txt'

                      Try `cp --help' for more information.

                       

                      when I use && cp %%OUTPUT_FILE in Linux.

                       

                      Thanks for sharing.

                      1 of 1 people found this helpful
                      • 8. Re: Getting a file via Control_m output upon ENDED OK ?
                        Mark Francome

                        It is strange that you don't see the variable when you do a listing but I think it's being set as you do see the cp file_0190211122426.txt

                         

                        So maybe it is the cp command that is the problem? Also, if you have spaces within the resolved variable then that causes problems. Best to enclose these in double quotes.

                        • 9. Re: Getting a file via Control_m output upon ENDED OK ?
                          Ram Iyer

                          Thanks for your reply. Do you mean wrapping the variable in double quotes like && cp "%%OUTPUT_FILE"

                           

                          The posted error point to Linux Usage: cp [OPTION]... [-T] SOURCE DEST

                           

                          We have source as "%%OUTPUT_FILE" , what is it for DEST ?

                           

                          Thanks for sharing .

                          • 10. Re: Getting a file via Control_m output upon ENDED OK ?
                            Mark Francome

                            Just as a simple first step, try this -

                             

                            cp -p %%OUTPUT_FILE /path/to/new/location

                             

                            putting the destination directory in instead of /path/to/new/location

                             

                            If the copy is needed in the same directory then -

                             

                            cp -p %%OUTPUT_FILE newfile.txt

                            • 11. Re: Getting a file via Control_m output upon ENDED OK ?
                              Ram Iyer

                              Thanks for your input.

                               

                              && cp -p %%OUTPUT_FILE newfile.txt is working upon main script ended OK.

                               

                              It is placing the file in new location as cp -p does

                               

                              My main thread is about getting this file, part of Control m shout out attachment notification of control M

                               

                              One more thing, if I make the OUTPUT_FILE as GLOBAL variable as shown in video. It is throwing CTMERR on this variable

                               

                              I did change to Local variable. Then it works, but not refreshing the variable content for each run. It retain previous value in this variable.

                               

                              Thanks for sharing.

                              • 12. Re: Getting a file via Control_m output upon ENDED OK ?
                                Mark Francome

                                CTMERR indicates the variable is not set. How do you set it when doing it as a global variable. If commands are we often have to escape them (the double % is not OS friendly).

                                • 13. Re: Getting a file via Control_m output upon ENDED OK ?
                                  Ram Iyer

                                  Thanks for your reply. I did define the variable as global (from drop down) shown in video.

                                   

                                  I did call as %%\OUTPUT_FILE in command.

                                   

                                  My main thread is about getting this file, part of Control m shout out attachment notification of control M , Any thoughts?

                                   

                                  Thanks for your guidance.