How to create a Folder Structure by a script

Hi!

I need to create a specific folder hierarchy within a shared folder. In each level of the hierarchy I need to set specific permissions that are not always inherited from the parent folder.
The same structure needs to be created on regular basis. The only difference will be the name of the root folder.

Is there a way in UCS to create such a folder hierarchy by script?
Or can I maybe set up a folder structure as a template and replicated it?

Thanks a lot,
Sanni

Hi,

there are several ways to do this. Apart from UCS-mechanics this sounds like you could write a (relatively simple) shell script based on mkdir and chown.
The important question is when and how you want it to be executed:

  • (Semi) automatically based on certain conditions or triggers
  • Manually with the root-folder name as input

If you want it the be run by itself, UCS offers different mechanisms. Could you explain your Use Case?

Hi jlk,

I don’t need the folders to be created by some trigger. Running a shell script manually will do the job. But I’m not aware how to set the permissions on the folders and sub-folders. Can I use the groups that are defined in the AD and just set them on the folders?

I mad a simple picture of the structure that I need to create:

FolderStructure

All folders are pre-defined and should not be editable. For each new customer the same structure shall be created. The groups (management, sales, production) exist in the AD. How do I set these group permissions within the script?

Thanks a lot,
Sanni

If a AD-Group is 1. synced to the UCS-LDAP und 2. belongs to the PosixGroup class, you can simply change the permission via chown like

chown -R :"Management Group" CUSTOMERS/AGENT_1/Customer_xy/MANAGEMENT

To verify if this is appliable you can run

getent group

Premissions based on owner and ownergroup can be set via chmod.

Another more modular approach would be to use an ACL, you can have a look at https://docs.software-univention.de/manual-4.4.html#domain-ldap:acls or https://help.univention.com/tag/acl for this.

1 Like

Thanks, this is very helpful!
Sanni

Mastodon