-
1. Re: How to pass the JobId to a nsh script (from a NshScriptJob)
Bill RobinsonMay 22, 2012 9:19 AM (in response to Clement BARRET)
1 of 1 people found this helpfulI have yet to find a way to do what you want.
I think you can derive the batch job key and possible the batch job run key from the nsh child jobs, if that’s the case, you can get the nsh child job run key.
Or you could re-work how this runs, and instead of using a batch job, use a nsh script to call the 1st script job, where you would have the run key after it finishes and then just start running whatever is in the second script.
-
2. Re: How to pass the JobId to a nsh script (from a NshScriptJob)
Clement BARRET May 22, 2012 9:35 AM (in response to Bill Robinson)Thanks @Bill Robinson for your answer.
I already thought I could "start the jobs using a nsh script" to get the JobId...
I wonder if I could avoid this since that would make "the following of the job run" very difficult (the first nsh script job is quite verbose since my nsh script prints some processing step messages on the STDOUT, which is pretty handy when you're following the job progress)...
That would be really great to have some dynamic variable (something like ??JOB.JOBID??) that could be passed to nsh scripts...
Damned, I either have to get the jobId using the job name (which force me to put a unique ID for each instance of the job in the job name... without being able to run it concurently) and get the last run log... OR try to do what you told me with a "nsh script launcher".
Basically, that should be a real pain in the ... since I will have to transmit job names in it... since every job "instances" have different parameters as well as different target lists :/
Damned... I'm screwed
Any idea or advice ?
-
3. Re: How to pass the JobId to a nsh script (from a NshScriptJob)
Bill RobinsonMay 22, 2012 9:38 AM (in response to Clement BARRET)
In the second script if you run ‘echo $0 it will give you filename of the script that’s running. I believe that might contain some useful information like the job run key. You might be able to back trace that to the batch job run, and from that get the job run of the 1st nsh job in the batch.
-
4. Re: How to pass the JobId to a nsh script (from a NshScriptJob)
Clement BARRET May 22, 2012 11:39 AM (in response to Bill Robinson)Well, I'm working on this really hard but I'm not going anywhere close to the solution...
I've created a nsh script job (type 2) to be able to "launch" both steps "manually".
Well, I wish I had not to do that since I will have to transmit the two job names and probably their "job group" also... which will be a real mess to maintain and to use (since I'm not responsible for the exploitation of things once their in production...).
Anyway, let's say I got this done, two job names as parameters plus the third one that would be the %h (targets list if I'm right).
How can I "launch" the first job transmitting the target list (as the first nsh script job is a type 1 one), get its dbkey ?
Then how can I wait for it to be finished before launching the second one (type 1 on a fixed target), transmitting the first job dbkey as a parameter ? (since this job already has many parameters already set, of the type "PARAM_NAME=VALUE" (which I parse in my nsh script to dynamically create a hash with param values).
Second solution (based on the $0) :
So, I print $0, "ok"
Where is the dbkey that could help me get the "sons log" in that name ?
For instance, my job actually print me this as $0 :
/opt/bmc/bladelogic/tmp/blasb01-js2/scripts/job__eabc2ba5-7906-4015-89fb-ee2c5a757489/script_DBKey-SJobKey-2147066-4__5ebe4bbd-1bff-4c3b-b651-a4efcc175706.2025174.1_test_job_args.nsh
Thanks again for your time and your help.
Regards.
-
5. Re: How to pass the JobId to a nsh script (from a NshScriptJob)
Clement BARRET May 23, 2012 12:17 PM (in response to Bill Robinson)Could you please give me some piece of code that would allow me to retrieve the run log of a NshScriptJob using a part of its name* (this part is unique) ?
(*) I must NOT have to use the "JobGroup" in the "query" since the Jobs will be located in several places in the Job tree...
Thanks in advance.
Regards.
-
6. Re: How to pass the JobId to a nsh script (from a NshScriptJob)
Bill RobinsonMay 23, 2012 12:21 PM (in response to Clement BARRET)
If you echo $0 from the second script you should have something like:
/opt/bmc/bladelogic/NSH/tmp/application_server/scripts/job__7f23f240-1e00-4eb1-9305-ec1be592b534/master_04cc5d2a-04ac-469d-8b10-6780e4dfbcbe
Right?
What version of bsa are you using ?
-
7. Re: How to pass the JobId to a nsh script (from a NshScriptJob)
Clement BARRET May 23, 2012 12:42 PM (in response to Bill Robinson)@Bill Robinson :
Atm we're using version 7.5 (or 7.6, duno exactly).
You can read my previous message to see I've given you what I got using $0.
Any idea ?
-
8. Re: How to pass the JobId to a nsh script (from a NshScriptJob)
Clement BARRET May 24, 2012 8:12 AM (in response to Clement BARRET)@Bill Robinson :
At least, could you please help me retrieving the last "run log" of a NshScriptJob (which run is over) given a (unique) part of its name (without knowing the Job's JobGroup name) ?
Thanks in advance.
Regards,
-
9. Re: How to pass the JobId to a nsh script (from a NshScriptJob)
Rohit Nayyar May 24, 2012 8:22 AM (in response to Clement BARRET)This is simple Perl code I have used to get the job id at run time of the job
Once u have the job id, you can use blcli to get its run id and other details
U can change this to NSH
my $script_path=$0;
$script_path=~tr/\\:/\//d;
my @temp=split("/",$script_path);
my $script_name=$temp[$#temp];
@temp=split("_",$script_name);
$temp[1]=~s/\-/:/;
$temp[1]=~s/\-/:/;
my $script_dbkey=$temp[1];
DB key is this variable $script_dbkey
-
10. Re: How to pass the JobId to a nsh script (from a NshScriptJob)
Clement BARRET May 24, 2012 8:36 AM (in response to Rohit Nayyar)@Bill Robinson :
Thanks for this,
I know perl quite well so I assume for the exemple ($0) you gave in your previous message
( /opt/bmc/bladelogic/NSH/tmp/application_server/scripts/job__7f23f240-1e00-4eb1-9305-ec1be592b534/master_04cc5d2a-04ac-469d-8b10-6780e4dfbcbe ) that would give to $script_dbkey the value :
04cc5d2a:04ac:469d-8b10-6780e4dfbcbe
is that right ?
-
11. Re: How to pass the JobId to a nsh script (from a NshScriptJob)
Clement BARRET May 24, 2012 9:17 AM (in response to Clement BARRET)I'm so pissed of the BladeLogic blcli implementation... How comes there is no such namespace as "this" since it's a java based framework ??
That's so insane to have to transmit metadata (JobGroup + JobName) to a script to allow it to get informations about its running status...
This is just a complete fail.
My need is quite BASIC and I can't find a proper way to achieve it...
I DON'T WANT to have to transmit the JobGroup to my "nsh script launcher" since it will be use in multiple cases with several nshscriptjobs to launch and monitor and that would be a real pain in the ass to set up for each instance...
Damned... I'm screwed... This is such a shame there is no way (by my somehow limitated knowledge, may be there is ?) to get "self" information from "inside" a nsh script...
Who designed this by the way ? Has he EVER had to code something useful ?
I'm quite angry since I don't have much time to finish this and I can't do it.
Pfff... I think that might me the end of this job for me...
-
12. Re: How to pass the JobId to a nsh script (from a NshScriptJob)
Bill RobinsonMay 25, 2012 3:59 PM (in response to Clement BARRET)
you have the key for the script itself, the trick is getting the job run id for the script and the batch job that job run is happening inside of. we could use something like getLastRunKeyByJobKey to get the job run key/id but that might not be the correct run id if you have multipe runs of the batch job happening concurrnetly.
if you think we can assume that the latest job run is the one you want i can proably work something out here, otherwise i'm still digging.
-
13. Re: How to pass the JobId to a nsh script (from a NshScriptJob)
Clement BARRET May 29, 2012 6:00 AM (in response to Bill Robinson)Well, I gave up on the "guess who was the first job" thing (because it's too slow to do a "recursive find" inside the jobs tree).
Instead, I designed a recursive find tool (that allows me to search only in a subtree jobs which name matches a given pattern) and I then get the DBKey and pass it as a parameter to my second job.
Then, in the second job, I just have to do :
blcli_execute JobRun findLastRunByJobKey <JOB_DBKEY>
blcli_execute JobRun getJobRunKey
and then (even if I wish I could do it another way, since I'll have to parse the output of this command and get only the lines with the "Exit Code x"...)
blcli_execute Utility exportNSHScriptResults <JOBRUN_KEY> <TMP_FILE>
Well, I'd like to get to this another way and I think there actually is one since the GUI is able to list the target servers on the left panel (right click on a job run then "Show Log") with only a green/red icon depending on the exit code... which is exactly what I need.
In fact, I wonder what are the kind of objects listed in this left panel...
Any idea to get this info straightforwardly assuming we got our job and jobrun dbkey ?
NB : in BladeLogic version 7.5, getLastRunKeyByJobKey doesn't exist
-
14. Re: How to pass the JobId to a nsh script (from a NshScriptJob)
Clement BARRET May 29, 2012 10:59 AM (in response to Clement BARRET)Well, I found something that could "be it" but I can't understand how to handle the list items I got...
I used the following commands :
blcli_execute JobRun findLastRunByJobKey <JOB_KEY>
blcli_execute JobRun getJobRunId
blcli_storeenv JOBRUN_ID
blcli_execute JobRun getFailedServersByRunId-api ${JOBRUN_ID}
and I got something like this :
[com.bladelogic.model.base.header.SDeviceHeaderImpl@1c2006a0, com.bladelogic.model.base.header.SDeviceHeaderImpl@7a9300cc]
This looks like a list but I really don't know how to iterate on each item of this list to get further details on each of them...
Any idea ?
Regards;