multiple folder creation using parameterised fixlet

Hi
I want to create a fixlet which will take input from parameter and create the folder in the unix and windows server. It something like it will ask to put the folder name along with path then it will read and create the folders. I’m able to create a parameter to input the folder name but I don’t know how to call it in the action script and the success criteria. I’m new to bigfix.

Hello!

Are you looking to create multiple folders, or just a single folder on multiple target endpoints using a single parameterized Fixlet?

Creating a single folder might be something as simple as the following (which I’ve not tested):

action parameter query "CreateFolder" with description "Please enter full path of the folder you'd like to create:"
folder create "{parameter "CreateFolder"}"
continue if {exists folder (parameter "CreateFolder)}

For reference to the actionscript commands above, please see:

https://developer.bigfix.com/action-script/reference/flow-control/action-parameter-query.html
https://developer.bigfix.com/action-script/reference/file/folder-create.html

Thank you for response. I want to create multiple folder in multiple targets. Like in the parameter field I will give the folder name then it will check whether the folder is exists or not. If not exists then it will create else it will email me what the folder is already exists and also email me what are the folder has been created.

<?xml version="1.0" encoding="UTF-8"?> UOB - SG - Folder Create - (SIT) - 14052019 - WIP true Internal 2019-05-20 x-fixlet-modification-time Thu, 23 May 2019 09:54:52 +0000 BESC Click here to deploy this action. action parameter query "CreateFolder" with description "Please Enter Full Path of the Folder you'd like to create:" folder create "{parameter "CreateFolder"}" continue if {exists folder (parameter "CreateFolder")}

Please help me to check the above code and let me know how can I call that parameter to create multiple folder or directory at a time. Looking for something I can create what mkdir -p does in unix. Please help

I haven’t really tested this, but it hopefully gives you an idea of one way to approach this:

action parameter query "CreateFolder" with description "Please enter full paths of the folder(s) you'd like to create (separated by ||):"

if {parameter "CreateFolder" does not contain "||"}
	folder create "{parameter "CreateFolder"}"
	continue if {exists folder (parameter "CreateFolder)}
endif


if {windows of operating system}
	delete __appendfile
	delete makedir.bat

	appendfile @echo off
	appendfile {concatenation "%0d%0a" of (("mkdir " & "%22" & it & "%22") of substrings separated by "||" of (parameter "CreateFolder"))}

	move __appendfile makedir.bat
	waithidden cmd /c makedir.bat

	delete makedir.bat
else
	delete __appendfile
	delete makedir.sh

	appendfile #!/bin/sh
	appendfile {concatenation "%0a" of (("mkdir -p " & "%22" & it & "%22") of substrings separated by "||" of (parameter "CreateFolder"))}

	move __appendfile makedir.sh
	wait chmod 755 makedir.sh
	wait "{pathname of client folder of current site & "/makedir.sh"}"
	
	delete makedir.sh
endif

At a high level, it dynamically creates a script on the endpoint based on the provided parameter value to create the desired folders. Sample parameter values might be: C:\foo||C:\bar or /foo||/bar||/tmp/foo

Hi Aram,

Thank you so much. It is working as per the expectation. can u pls suggest me some good books to learn this language.

My favorite resource for learning Relevance is the PDF class that I took long long ago:
http://support.bigfix.com/fixlet/documents/CustomAuthoringTrainingGuide-6-17-2005.pdf

The newer, but less comprehensive relevance tutorial is also nice:
https://developer.bigfix.com/relevance/tutorial.html

If you prefer video to reading:

3 Likes

Hi Aram,

I’m looking for an option in the fixlet that after input the folder name it will display folder creation command along with the folder name. It is just a purpose for verify that the folder name has been keyed in correctly. Actually this requirement is from my manager. Appreciate if you could help me on this. Thank you in Advance.

The standard action parameter query method does not currently provide many options for the use case of displaying additional messaging and/or confirmation. It is possible to do what you’ve asked via parameterized Fixlets, though this will require some additional scripting (javascript). I’d recommend taking a look at the following for more information:

Hi Aram,

sorry for my late response. Thank you so much for the details explanation. I will try the way you mentioned. I need another help from you. Below condition is showing as failed.

action parameter query “Remote_CDID” with description "Please Enter the Remote Node CD ID:"
action parameter query “Remote_Node” with description "Please Enter the Remote Server CD Node Name:"
action parameter query “Local_CDID” with description “Please Enter the Local CD ID:”

continue if {not exists lines whose (it contains (parameter “Remote_CDID”)@(parameter “Remote_CDID”)) of file " /syslv/scripts/sys_info/userfile.cfg"}

Error Message: Command failed (Relevance substitution failed) continue if {not exists lines whose (it contains {parameter “Remote_CDID”}@{parameter “Remote_CDID”}) of file " /syslv/scripts/sys_info/test.cfg"} (action:29791)

I need to check the “Remote_CDID@Remote_Node” is exists in the file or not. But it giving me command failed. Please help

I’ve not tested this, but perhaps something like the following might work:

action parameter query “Remote_CDID” with description “Please Enter the Remote Node CD ID:”
action parameter query “Remote_Node” with description “Please Enter the Remote Server CD Node Name:”
action parameter query “Local_CDID” with description “Please Enter the Local CD ID:”

continue if {not exists lines whose (it contains (parameter “Remote_CDID” of action as string & “@” & parameter “Remote_Node” of action as string)) of file “/syslv/scripts/sys_info/userfile.cfg”}

Hi Aram,

Thank you for your prompt response. It is failed.

Command failed (Relevance substitution failed) continue if {not exists lines whose (it contains (parameter “Remote_CDID”) of action as string & “@” & (parameter “Remote_Node” of action as string)) of file " /syslv/scripts/sys_info/userfile.cfg"}

Hi Aram,

Ignore my earlier message. it is working now and problem was in the space in the invited comma. But now I need your help for the below.

I need to look for an word in a file whether it is exists or not after a cdadmin word in the file.
In the file I’ve the below entry.
cdadmin:
:admin.auth=y:
:pstmt.copy.ulimit=y:
:pstmt.upload=y:
:pstmt.upload_dir=:
:pstmt.download=y:
:pstmt.download_dir=:
:pstmt.run_dir=:
:pstmt.submit_dir=:
:name=:
:phone=:
:descrip=:
so I want an condition which will start search after this cdadmin entries. condition won’t look for any entries above the cdadmin word. Please help me to achieve this. Thank you

I tried the below but failed

Command failed (Relevance substitution failed) continue if {not exists lines whose (name of it as uppercase starts with (parameter “Local_CDID” of action as string)) of file “/syslv/scripts/sys_info/userfile.cfg”} (action:29811)

I need to match whether the parameter local_cdid is exists as uppercase and starts the line with this name in the file or not. Please help

Are you asking to check the line in the file that starts with :name=: (the first instance after a line that starts with cdadmin:) for a particular uppercase value?

HI Aram,
From cdadmin till descript=: is a whole stanza. I would be couple stanza like this but those won’t be start with cdadmin. Those will be start with some other username and those username would be uppercase. I want the pattern matching criteria will be start after the cdadmin stanza. There might be same name above the cdadmin but those shouldn’t be check.

Please see a sample content in the configuration file below.
TESTR@CD.TEST:
:local.id=TEST:
:pstmt.upload=y:
:pstmt.upload_dir=:
:pstmt.upload_dir=:
:pstmt.download=y:
:pstmt.download_dir=/cdtransfer/:
:pstmt.run_dir=:
:pstmt.submit_dir=:
:descrip=:
cdadmin:
:admin.auth=y:
:pstmt.copy.ulimit=y:
:pstmt.upload=y:
:pstmt.upload_dir=:
:pstmt.download=y:
:pstmt.download_dir=:
:pstmt.run_dir=:
:pstmt.submit_dir=:
:name=:
:phone=:
:descrip=:

TEST:
:admin.auth=n:
:cmd.chgproc=y:
:cmd.delproc=y:
:cmd.flsproc=y:
:cmd.selproc=y:
:cmd.submit=y:
:cmd.selstats=y:
:cmd.stopndm=n:
:cmd.trace=n:
:pstmt.copy=y:
:pstmt.runjob=y:
:pstmt.runtask=y:
:pstmt.submit=y:
:snode.ovrd=y:
:pstmt.copy.ulimit=y:
:pstmt.upload=y:
:pstmt.upload_dir=:
:pstmt.download=y:
:pstmt.download_dir=:\

Thank you

Assuming that the fields and field order in the file are consistent (which may not be a fair assumption), we can use a bit of a shortcut to return contents of the :name=: line after cdadmin: with something like this:

line (line number of line whose (it as string starts with "cdadmin:") of it + 9) of file "/syslv/scripts/sys_info/userfile.cfg"

We can also parse out the :name= to just the field data with something like:

preceding text of last ":" of following text of first ":name=" of line (line number of line whose (it as string starts with "cdadmin:") of it + 9) of file "/syslv/scripts/sys_info/userfile.cfg"

By the way, in case you’re not already doing so, you can test/develop these relevance statements via QNA or Query prior to using them for substitution in actionscript.

Hi Aram,

I need your help for the below analysis

if (exists lines whose (((it contains “x.x.x.x” AND it does not start with “#”) AND it as lowercase contains “host1”)) of file “/etc/hosts”) then (“Passed”) else (“Failed”)

how can I write the above one to check for multiple lines in the file.