Determine path available and set variable for that path name

I have 3 different paths on our windows servers. I have to identify which one is present, set that in a variable and use the variable in the script that part of a bigger path.

For example we can have: e:\apps\redhat\jboss-ews-2.0 or e:\apps\redhat\jboss-ews-3.0

I want to identify what path is present, save in a variable and use it as part of bigger paths in the script.

Hope this make sense. TIA, Ken

To set the “variable”, referred to as Parameters in Action script.
https://developer.bigfix.com/action-script/reference/flow-control/parameter.html

NOTE: I used the if/elseif/endif structure in case more than one of the folders exists on a system. This will prevent errors that occur if the same Parameter value is set twice in an Action.

if {exists folder "e:\apps\redhat\jboss-ews-2.0"}
parameter "foundPath"="e:\apps\redhat\jboss-ews-2.0"
elseif {exists folder "e:\apps\redhat\jboss-ews-3.0"}
parameter "foundPath"="e:\apps\redhat\jboss-ews-3.0"
endif

To use the Parameter value later …

{Parameter "foundPath"}

1 Like

Thanks for your fast reply @TimRice. That makes perfect sense.

But to complicate matters even further, I can have 2 versions (paths) present. For instance, I can have jboss-ews-2.0 and jboss-ews-3.0. Or I can have 3.0 and 3.1. I cannot think of a clean way to first update one version (say ews-2.0) and then make a second pass and update ews-3.0 unless I set a flag for the second pass.

Do you happen to have a better idea?

TIA,
Ken

At that point, I would stop trying to be “cute” about the code and pull out the brute force method.

You could simply make the Relevance for the Fixlet detect ANY of the paths.

(exists Folder "e:\apps\redhat\jboss-ews-2.0") OR (exists Folder "e:\apps\redhat\jboss-ews-3.0") OR (exists Folder "e:\apps\redhat\jboss-ews-3.1")

Then have the Action script account for any of the folders using a collection of “IF/ENDIF” statements, one after another.

if {exists Folder "e:\apps\redhat\jboss-ews-2.0"}
whatever-needs-to-be-done-to e:\apps\redhat\jboss-ews-2.0
endif

if {exists Folder "e:\apps\redhat\jboss-ews-3.0"}
whatever-needs-to-be-done-to e:\apps\redhat\jboss-ews-3.0
endif

if {exists Folder "e:\apps\redhat\jboss-ews-3.1"}
whatever-needs-to-be-done-to e:\apps\redhat\jboss-ews-3.1
endif

Adding as many iterations of the IF/ENDIF clause as needed, with the folders included in the Relevance clause. This way, if there are multiple instances on a system, they will all be addressed by the same Action.

Yeah I could see that logic being necessary now. It will make my script 3 times as big, but you do what you have to do. Thanks for the ideas Tim.

Ken

So I combined the 3 scripts and got this error in the 3rd portion. I don’t see the error and the code should be almost the same in all 3 sections.

Do you see the error/problem?

if {exists Folder “e:\apps\redhat\jboss-ews-2.0”}
// UPDATE Tomcat EWS 2.0 for Java 7
appendfile mkdir D:\SVC_DEL\bkup
appendfile mkdir D:\Apps
appendfile set STD_JAVA_PATH=E:\Apps\Redhat\jboss-ews-2.0\java
appendfile if exist %STD_JAVA_PATH%\jre\lib\security\cacerts copy %STD_JAVA_PATH%\jre\lib\security\cacerts d:\SVC_DEL\bkup
appendfile if exist %STD_JAVA_PATH%\jre\lib\security\local_policy.jar copy %STD_JAVA_PATH%\jre\lib\security\local_policy.jar d:\SVC_DEL\bkup
appendfile if exist %STD_JAVA_PATH%\jre\lib\security\US_export_policy.jar copy %STD_JAVA_PATH%\jre\lib\security\US_export_policy.jar d:\SVC_DEL\bkup
appendfile if exist %STD_JAVA_PATH%\jre\lib\security\java.security copy %STD_JAVA_PATH%\jre\lib\security\java.security d:\SVC_DEL\bkup
if { exists file “e:\Apps\Redhat\temp.bat”}
delete "e:\Apps\Redhat\temp.bat"
endif
copy “__appendfile” “e:\Apps\Redhat\temp.bat"
dos “e:\Apps\Redhat\temp.bat”
// wait wmic service where “pathname like ‘%redhat%’” call ChangeStartmode Disabled > d:\Apps\output.txt
dos net start |findstr /i tomcat > d:\Apps\tomcat.txt
dos wmic service where “pathname like ‘%tomcat%’” call ChangeStartmode Disabled > d:\Apps\output.txt
dos wmic service where “pathname like ‘%tomcat%’” call stopservice >> d:\Apps\output.txt
dos wmic process where “executablepath like ‘%tomcat%’” get commandline > d:\Apps\process.txt
dos wmic process where “executablepath like ‘%tomcat%’” call terminate >> d:\Apps\output.txt
parameter “startTime”=”{now}"
pause while { (now-time(parameter “startTime”) < 45second) }
if { exists file “java.exe” whose (version of it >= “7”) of folder “E:\Apps\Redhat\jboss-ews-2.0\java\jre\bin”}
dos rd E:\Apps\Redhat\jboss-ews-2.0\java /s /q
parameter “startTimeone”="{now}"
pause while { (now-time(parameter “startTimeone”) < 45
second) }
dos mkdir E:\Apps\Redhat\jboss-ews-2.0\java
dos echo Java 7 > d:\Apps\java.txt
prefetch 58c59727e258b475e2c0825ba23e42bd6e488354 sha1:58c59727e258b475e2c0825ba23e42bd6e488354 size:150090018 http://p3piemc01.rb.win.frb.org:52311/Uploads/58c59727e258b475e2c0825ba23e42bd6e488354/Java_1.7.171.tmp sha256:cb807e60909fe1bb96f06d1142f77652959fc1247340ff445a013cf5174268d4
extract 58c59727e258b475e2c0825ba23e42bd6e488354 E:\Apps\Redhat\jboss-ews-2.0\java
endif
dos copy d:\SVC_DEL\bkup\cacerts E:\Apps\Redhat\jboss-ews-2.0\java\jre\lib\security
dos copy d:\SVC_DEL\bkup\local_policy.jar E:\Apps\Redhat\jboss-ews-2.0\java\jre\lib\security
dos copy d:\SVC_DEL\bkup\US_export_policy.jar E:\Apps\Redhat\jboss-ews-2.0\java\jre\lib\security
dos copy d:\SVC_DEL\bkup\java.security E:\Apps\Redhat\jboss-ews-2.0\java\jre\lib\security
dos wmic service where “pathname like ‘%tomcat%’” call ChangeStartmode Automatic >> d:\Apps\output.txt
dos wmic service where “pathname like ‘%tomcat%’” call startservice >> d:\Apps\output.txt
dos net start |findstr /i tomcat >> d:\Apps\tomcat.txt
//
endif
// EWS-3.0
if { exists folder “e:\apps\redhat\jboss-ews-3.0” }
appendfile mkdir D:\SVC_DEL\bkup
appendfile mkdir D:\Apps
appendfile set STD_JAVA_PATH=E:\Apps\Redhat\jboss-ews-3.0\java
appendfile if exist %STD_JAVA_PATH%\jre\lib\security\cacerts copy %STD_JAVA_PATH%\jre\lib\security\cacerts d:\SVC_DEL\bkup
appendfile if exist %STD_JAVA_PATH%\jre\lib\security\local_policy.jar copy %STD_JAVA_PATH%\jre\lib\security\local_policy.jar d:\SVC_DEL\bkup
appendfile if exist %STD_JAVA_PATH%\jre\lib\security\US_export_policy.jar copy %STD_JAVA_PATH%\jre\lib\security\US_export_policy.jar d:\SVC_DEL\bkup
appendfile if exist %STD_JAVA_PATH%\jre\lib\security\java.security copy %STD_JAVA_PATH%\jre\lib\security\java.security d:\SVC_DEL\bkup
if { exists file “e:\Apps\Redhat\temp.bat”}
delete "e:\Apps\Redhat\temp.bat"
endif
copy “__appendfile” “e:\Apps\Redhat\temp.bat"
dos “e:\Apps\Redhat\temp.bat”
// wait wmic service where “pathname like ‘%redhat%’” call ChangeStartmode Disabled > d:\Apps\output.txt
dos net start |findstr /i tomcat > d:\Apps\tomcat.txt
dos wmic service where “pathname like ‘%tomcat%’” call ChangeStartmode Disabled > d:\Apps\output.txt
dos wmic service where “pathname like ‘%tomcat%’” call stopservice >> d:\Apps\output.txt
dos wmic process where “executablepath like ‘%tomcat%’” get commandline > d:\Apps\process.txt
dos wmic process where “executablepath like ‘%tomcat%’” call terminate >> d:\Apps\output.txt
parameter “startTime”=”{now}"
pause while { (now-time(parameter “startTime”) < 45second) }
if { exists file “java.exe” whose (version of it >= “8”) of folder “E:\Apps\Redhat\jboss-ews-3.0\java\jre\bin”}
dos rd E:\Apps\Redhat\jboss-ews-3.0\java /s /q
parameter “startTimeone”="{now}"
pause while { (now-time(parameter “startTimeone”) < 45
second) }
dos mkdir E:\Apps\Redhat\jboss-ews-3.0\java
dos echo Java 8 > d:\Apps\java.txt
prefetch 7a976126efbbe2bb2151caa57acdf559a33de91b sha1:7a976126efbbe2bb2151caa57acdf559a33de91b size:186998372 http://p3piemc01.rb.win.frb.org:52311/Uploads/7a976126efbbe2bb2151caa57acdf559a33de91b/Java_1.8.162.tmp sha256:2b79ce678134b010492e64e41c160c846dcaa932874f413fd52aeb401a064edb
extract 7a976126efbbe2bb2151caa57acdf559a33de91b E:\Apps\Redhat\jboss-ews-3.0\java
endif
dos copy d:\SVC_DEL\bkup\cacerts E:\Apps\Redhat\jboss-ews-3.0\java\jre\lib\security
dos copy d:\SVC_DEL\bkup\local_policy.jar E:\Apps\Redhat\jboss-ews-3.0\java\jre\lib\security
dos copy d:\SVC_DEL\bkup\US_export_policy.jar E:\Apps\Redhat\jboss-ews-3.0\java\jre\lib\security
dos copy d:\SVC_DEL\bkup\java.security E:\Apps\Redhat\jboss-ews-3.0\java\jre\lib\security
dos wmic service where “pathname like ‘%tomcat%’” call ChangeStartmode Automatic >> d:\Apps\output.txt
dos wmic service where “pathname like ‘%tomcat%’” call startservice >> d:\Apps\output.txt
dos net start |findstr /i tomcat >> d:\Apps\tomcat.txt
endif
// EWS 3.1
if { exists folder “e:\apps\redhat\jboss-ews-3.1” }
appendfile mkdir D:\SVC_DEL\bkup
appendfile mkdir D:\Apps
appendfile set STD_JAVA_PATH=E:\Apps\Redhat\jboss-ews-3.1\java
appendfile if exist %STD_JAVA_PATH%\jre\lib\security\cacerts copy %STD_JAVA_PATH%\jre\lib\security\cacerts d:\SVC_DEL\bkup
appendfile if exist %STD_JAVA_PATH%\jre\lib\security\local_policy.jar copy %STD_JAVA_PATH%\jre\lib\security\local_policy.jar d:\SVC_DEL\bkup
appendfile if exist %STD_JAVA_PATH%\jre\lib\security\US_export_policy.jar copy %STD_JAVA_PATH%\jre\lib\security\US_export_policy.jar d:\SVC_DEL\bkup
appendfile if exist %STD_JAVA_PATH%\jre\lib\security\java.security copy %STD_JAVA_PATH%\jre\lib\security\java.security d:\SVC_DEL\bkup
if { exists file “e:\Apps\Redhat\temp.bat”}
delete "e:\Apps\Redhat\temp.bat"
endif
copy “__appendfile” “e:\Apps\Redhat\temp.bat"
dos “e:\Apps\Redhat\temp.bat”
// wait wmic service where “pathname like ‘%redhat%’” call ChangeStartmode Disabled > d:\Apps\output.txt
dos net start |findstr /i tomcat > d:\Apps\tomcat.txt
dos wmic service where “pathname like ‘%tomcat%’” call ChangeStartmode Disabled > d:\Apps\output.txt
dos wmic service where “pathname like ‘%tomcat%’” call stopservice >> d:\Apps\output.txt
dos wmic process where “executablepath like ‘%tomcat%’” get commandline > d:\Apps\process.txt
dos wmic process where “executablepath like ‘%tomcat%’” call terminate >> d:\Apps\output.txt
Failed parameter “startTime”=”{now}"
pause while { (now-time(parameter “startTime”) < 45second) }
if { exists file “java.exe” whose (version of it >= “8”) of folder “E:\Apps\Redhat\jboss-ews-3.1\java\jre\bin”}
dos rd E:\Apps\Redhat\jboss-ews-3.1\java /s /q
parameter “startTimeone”="{now}"
pause while { (now-time(parameter “startTimeone”) < 45
second) }
dos mkdir E:\Apps\Redhat\jboss-ews-3.1\java
dos echo Java 8 > d:\Apps\java.txt
prefetch 7a976126efbbe2bb2151caa57acdf559a33de91b sha1:7a976126efbbe2bb2151caa57acdf559a33de91b size:186998372 http://p3piemc01.rb.win.frb.org:52311/Uploads/7a976126efbbe2bb2151caa57acdf559a33de91b/Java_1.8.162.tmp sha256:2b79ce678134b010492e64e41c160c846dcaa932874f413fd52aeb401a064edb
extract 7a976126efbbe2bb2151caa57acdf559a33de91b E:\Apps\Redhat\jboss-ews-3.1\java
endif
dos copy d:\SVC_DEL\bkup\cacerts E:\Apps\Redhat\jboss-ews-3.1\java\jre\lib\security
dos copy d:\SVC_DEL\bkup\local_policy.jar E:\Apps\Redhat\jboss-ews-3.1\java\jre\lib\security
dos copy d:\SVC_DEL\bkup\US_export_policy.jar E:\Apps\Redhat\jboss-ews-3.1\java\jre\lib\security
dos copy d:\SVC_DEL\bkup\java.security E:\Apps\Redhat\jboss-ews-3.1\java\jre\lib\security
dos wmic service where “pathname like ‘%tomcat%’” call ChangeStartmode Automatic >> d:\Apps\output.txt
dos wmic service where “pathname like ‘%tomcat%’” call startservice >> d:\Apps\output.txt
dos net start |findstr /i tomcat >> d:\Apps\tomcat.txt
endif

The error seems to be coming from …

parameter "startTime"="{now}"

I’m just guessing here, but I’d be willing to bet that one of the previous sections ran, and that the Parameter “startTime” had already been set. The problem is that each Parameter can ONLY be set ONCE per Action. If you set the same Parameter again in the Action, you will get a Failure.

I recommend you use a different Parameter name for each section to avoid this problem.

I think you hit the nail on the head about parameter re-use problem. It never occurred to me.

I changed the parameters to be unique and ran a test. It worked flawlessly.

Thanks for all your help Tim.

Ken