Absent Member.. Absent Member..
Absent Member..
1598 views

Anyway to use bash scripts in execution steps

Jump to solution

Hi,

 

In an execution step I am trying to use some bash scripts but somehow I could not manage.

I am not sure if I am doing something wrong or it is not supported.

My example is as follows.

 

if [ "[REQ.VP.KNTA_PROJECT_TYPE]" = "Technical Infrastructure" ]
then
  ksc_itg_run_sql QUERY_STRING="SELECT project_type_id  FROM pm_project_types WHERE project_type_name='Technical Infrastructure Old'"
  ksc_store REQ.P.KNTA_PROJECT_TYPE="[SQL_OUTPUT]", "Technical Infrastructure Old"
fi

ksc_comment "done"

 

It comes up with an error as

"Unknown or out of sequence command

[if [ "Technical Infrastructure Old" = "Technical Infrastructure" ]]

" in the log.

 

Any help is appreciated

 

Regards

T.M.

 

Tags (1)
0 Likes
1 Solution

Accepted Solutions
Cadet 1st Class
Cadet 1st Class

Can you please post the full command you are using?

 

I think you can specify an IF condition within a command scope - you cannot use it outside of command scope. Based on your original post your IF statment is out of command scope. 

 

 

For out of command scope there is a Condition parameter (see attached).

Share Knowledge

View solution in original post

9 Replies
Cadet 1st Class
Cadet 1st Class
I think you are missing ";" in number of places and closing "]".

try this:

if [ "[REQ.VP.KNTA_PROJECT_TYPE]" = "Technical Infrastructure" ] ];
then
ksc_itg_run_sql QUERY_STRING="SELECT project_type_id FROM pm_project_types WHERE project_type_name='Technical Infrastructure Old'"
ksc_store REQ.P.KNTA_PROJECT_TYPE="[SQL_OUTPUT]", "Technical Infrastructure Old" ;
fi
ksc_comment "done"


Thanks,
Share Knowledge
0 Likes
Absent Member.. Absent Member..
Absent Member..

Thanks,

 

But still the same problem.

 

0 Likes
Cadet 1st Class
Cadet 1st Class

Can you please post the full command you are using?

 

I think you can specify an IF condition within a command scope - you cannot use it outside of command scope. Based on your original post your IF statment is out of command scope. 

 

 

For out of command scope there is a Condition parameter (see attached).

Share Knowledge

View solution in original post

Absent Member.. Absent Member..
Absent Member..

My full command:

#Get Project id for 'Technical Infrastructure Old'
ksc_comment "Project type id: [REQ.P.KNTA_PROJECT_TYPE]"
ksc_comment "Project type name: [REQ.VP.KNTA_PROJECT_TYPE]"
if [ "[REQ.VP.KNTA_PROJECT_TYPE]" = "Technical Infrastructure" ] ;
then
  ksc_itg_run_sql QUERY_STRING="SELECT project_type_id  FROM pm_project_types WHERE project_type_name='Technical Infrastructure Old'"
  ksc_store REQ.P.KNTA_PROJECT_TYPE="[SQL_OUTPUT]", "Technical Infrastructure Old"
fi
ksc_comment "ok"

 

In my command, condition parameter is blank.

 

0 Likes
Fleet Admiral
Fleet Admiral

It's likely trying to parse your bash conditional

 

[if [ "Technical Infrastructure Old" = "Technical Infrastructure" ]]

 

as a token, and coming up confused.

 

You might want to just encapsulate the logic in a shell script or a db function and just call it using the [REQ.VP.KNTA_PROJECT_TYPE] as input.

0 Likes
Absent Member.. Absent Member..
Absent Member..

Thanks All,

 

I think, there is no way of using bash scripts in execution steps.

Anyhow, I managed to made it work through "condition" parameter as follows

 

condition :  

'[REQ.VP.KNTA_PROJECT_TYPE]' = 'Technical Infrastructure'

in Steps:

#Get Project id for 'Technical Infrastructure Old'
ksc_comment "Project type id: [REQ.P.KNTA_PROJECT_TYPE]"
ksc_comment "Project type name: [REQ.VP.KNTA_PROJECT_TYPE]"
ksc_itg_run_sql QUERY_STRING="SELECT project_type_id  FROM pm_project_types WHERE project_type_name='Technical Infrastructure Old'"
ksc_store REQ.P.KNTA_PROJECT_TYPE="[SQL_OUTPUT]", "Technical Infrastructure Old"
ksc_comment "ok"

 

Even though this solves my problem, I am not happy with the solution.

I prefer script-style steps.

I attached an image.

 

Regards

T.M.

0 Likes
Cadet 1st Class
Cadet 1st Class
as I said, you can use IF statements within command scopes - for example ksc_connect_dest_server. Once the command reaches the server, your IF statements will be executed no problem. I just set it up on my environment. For out of command scope Condition parameter should be used.
Share Knowledge
0 Likes
Absent Member.. Absent Member..
Absent Member..

But, it didn't work.

Anyway, I applied you suggestion it worked.

You've got my kudos. 

 

Thanks

0 Likes
Absent Member.. Absent Member..
Absent Member..

PPM does not understand Bash. In order to execute a Bash command you need to log in to a server or use the ksc_local_exec special command. PPM will then pass the commands to Bash for execution. Note that conditional statements like if..fi need to be placed on a single command line. Bash conditional statements cannot be used to control execution of PPM special commands, though. The method you ended up using, placing the condition on the command step, is the best method for what you are doing here.

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.