-
1. Re: Getting a file via Control_m output upon ENDED OK ?
Mark Francome Jan 25, 2019 3:26 AM (in response to Ram Iyer)3 of 3 people found this helpfulDo 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 ....
-
2. Re: Getting a file via Control_m output upon ENDED OK ?
Juan Pablo Ojeda Jan 25, 2019 6:04 AM (in response to Mark Francome)2 of 2 people found this helpfulHi 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!
-
3. Re: Getting a file via Control_m output upon ENDED OK ?
Ram Iyer Feb 8, 2019 1:31 PM (in response to Juan Pablo Ojeda)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 Feb 9, 2019 8:41 AM (in response to Ram Iyer)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 Feb 9, 2019 10:32 AM (in response to Mark Francome)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 Feb 10, 2019 5:42 AM (in response to Ram Iyer)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 Feb 11, 2019 4:02 PM (in response to Mark Francome)1 of 1 people found this helpfulThanks 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.
-
8. Re: Getting a file via Control_m output upon ENDED OK ?
Mark Francome Feb 12, 2019 7:56 AM (in response to Ram Iyer)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 Feb 12, 2019 9:23 AM (in response to Mark Francome)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 Feb 12, 2019 10:08 AM (in response to Ram Iyer)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 Feb 12, 2019 12:08 PM (in response to Mark Francome)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 Feb 14, 2019 7:20 AM (in response to Ram Iyer)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 Feb 14, 2019 9:37 AM (in response to Mark Francome)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.