v10.17 (build: May 28 2024)

Data synchronization tool

The stcsvsync tool creates an SQL script for synchronize settings based on data provided in .csv table and several types of conversion.

Tool can be downloaded here



General rules

Input data must be provided as .csv (divider - semicolon ";"). File encoding UTF-8.

Output data will be in UTF-8 encoding.

Errors and warnings will be sent to STDERR, output data without setting output file - to STDOUT.

Tip: if you just starting to use the tool, avoid [-of -o] parameters. In that case output format will be set as TEXT, and you'll get visually appealed data on screen, and can evaluate results before making database changes.



Common command line parameters

-i [--input] - input file. Base functions won't be available if not set.

-o [--output] - output file. Result will be seen at terminal window if not set.

-of [--output-format] - format for output data TEXT (default), MSSQL, PGSQL.

-t [--type] - type of data conversion. D - Employee Dossier, H - Company structure, S Managers, V - Holidays / sick leave.

-tt [--template] - get .csv template for choosen conversion type [--type].

How to get template .csv file for company structure:

> stcsvsync -t H -tt
id;parent;name;[user;[NB_domain]];[computer;[FQ_domain]]

Template for employee profiles:

> stcsvsync -t D -tt -o dos_template.csv
> cat dos_template.csv
user;[NB_domain];[fio];[department];[contacts];[profile]


Command line parameters
shortfullconversion typedescription
-h--helpshow usage
-i--inputinput file name
-o--outputoutput file name
-of--output-formatOutput format: [MSSQL | PGSQL | TEXT] default: TEXT
-t--typeConversion type: D | H | S | V (Dossier, Hierarchy, Subordination, Vacation)
-ns--no-sort[DHSV]disable sorting before output
-tt--template[DHSV]produce .csv template for provided conversion type
-hl--header-lines[DHSV]number of lines represents header in .csv file [0..] default: 1
-dnb--domain-netbios[DHSV]NB_domain in NETBIOS format. Applies when NB_column is omitted
-dfq--domain-fqdn[H]Domain name (FQ_domain) FQDN format. Applies when FQ_domain is omitted
-ci--column-id[HS]id column number
-cp--column-parent[HS]parent column number
-cn--column-name[H]name column number
-cu--column-user[DHSV]user column number
-cc--column-computer[H]computer column number
-cnb--column-domain-netbios[DHSV]NB_domain column number
-cfq--column-domain-fqdn[H]FQ_domain column number
-cf--column-fio[D]fio column number or format string or constant string
-cd--column-department[D]department column number or format string or constant string
-ct--column-contacts[D]contacts column number or format string or constant string
-cpr--column-profile[D]profile column number or format string или constant string
-nd--no-depth[S]forbids to manage subsequent hierarchy nodes
-cb--column-boss[S]boss column number
-bv--boss-value[S]boss column match value
-dbu--db-user-template[S]Existing SQL user login, which rights will be copied to created users
-cvb--column-vacation-begin[V]begin date of vacation column number
-cve--column-vacation-end[V]end date of vacation column number
-cvr--column-vacation-reason[V]reason column number


Company Structure

(see referenced topic at "Global settings" here)

ATTENTION: target SQL-script will completely delete existing company structure, and deploy new structure afterwards!

Hierarchy nodes can represent groups (departments), users and computers

You can get different kind of company structure, based on single input file.

  1. Company Structure (departments only)
  2. > stcsvsync -i example.csv -t H -ci A -cp B -cn C
  3. Departments + users
  4. > stcsvsync -i example.csv -t H -ci A -cp B -cn C -cu D -cnb E
  5. Deparments + computers
  6. > stcsvsync -i example.csv -t H -ci A -cp B -cn C -cc F -cfq G
  7. Departments + user + computer (full structure)
  8. > stcsvsync -i example.csv -t H -ci A -cp B -cn C -cu D -cnb E -cc F -cfq G

Example of full organization structure built from example.csv

> stcsvsync -i example.csv -t H -ci A -cp B -cn C -cu D -cnb E -cc F -cfq G
base tableproduced structure
Table example.csv
ABCDEFGH
1idparentnameusernetbios_domaincomputerfqdn_domainboss
211Company
321Department 1
431Department 2
542Sub department 1.1
651Sub department 1.2
765Sub department 1.2.1user1COMPANYcomputer1company.comyes
865Sub department 1.2.1user2COMPANYcomputer2company.com
965Sub department 1.2.1user3COMPANYcomputer3company.com
105user4COMPANYcomputer4company.com
114user5COMPANYcomputer5company.comyes
124user6COMPANYcomputer6company.com
131COMPANY\user7computer7.company.com
142user8COMPANYcomputer8company.comyes
153user9COMPANYcomputer9company.com
Company
  COMPANY\user7
  COMPUTER7.company.com
  Department 1
    COMPANY\user8
    COMPUTER8.company.com
    Sub department 1.1
      COMPANY\user5
      COMPANY\user6
      COMPUTER5.company.com
      COMPUTER6.company.com
  Department 2
    COMPANY\user9
    COMPUTER9.company.com
  Sub department 1.2
    COMPANY\user4
    COMPUTER4.company.com
    Sub department 1.2.1
      COMPANY\user1
      COMPANY\user2
      COMPANY\user3
      COMPUTER1.company.com
      COMPUTER2.company.com
      COMPUTER3.company.com

Lines 2-6 tells only about groups (departments).
Lines 7-9 besides hierarchy tells about user and computer.
Lines 10-15 don't contain any departments info, but only add users and computers.

Do notice how different results are produced for line 9 and line 10.
 Line 10 add user user4 and computer computer4 to parent Node 5 (Sub department 1.2).
 Line 9, despite having same parent 5 (Sub department 1.2), adds user3 and computer3 to Node 6 (Sub department 1.2.1), which is descendant of Node 5.
You should keep this in mind when constructing the initial table.

 Line 13 shows how to use Domain name with users and computers in same cell (so you don't need to have separate column for domains).


Synchronizing managers

(see referenced topic at "Global settings" here)

The tool expects that there is a template user in the settings, whose rights will be copied when creating new users.
Create this user without using the "\" character in his name (see the following note below)

ATTENTION:
 target SQL-script will delete users, whose names contain "\" character. For example DOMAIN\username.
 Tool has no way to check if template user exists or not [--db-user-template]. Otherwise, the newly created user will have empty set of rights, and you will have to set the rights manually trough the "Global settings".

> stcsvsync -i example.csv -t S -ci A -cp B -cn C -cu D -cnb E -cb H -dbu template_user

user8 is a Manager for all users and computers of Department 1 and all subsequent groups, users and computers
user5 is a Manager for all users and computers of Sub department 1.1 and all subsequent ...
user1 is a Manager for all users and computers of Sub department 1.2.1 and all subsequent ...

You can change default behavior with key [--no-depth]

> stcsvsync -i example.csv -t S -ci A -cp B -cn C -cu D -cnb E -cb H -nd -dbu template_user

user8 is a Manager for user8
user5 is a Manager for user5, user6
user1 is a Manager for user1, user2, user3



Employee profiles

(see referenced topic at "Global settings" here)

Table userinfo.csv

ABCDEFG
1usernetbios_domainlastnamefirstnamedepartmente-mailphone
2user1COMPANYSmithJohnitjohn@company.com111-222-33-44
3user2COMPANYWhiteJaneitjane@company.com111-222-33-45
4user3COMPANYHarrisonHarryitharry@company.com111-222-33-46
5user4COMPANYRobbinsOscarmanagementoscar@company.com111-222-33-47
6user5COMPANYDavisMilessalesmiles@company.com111-222-33-48
7user6COMPANYMorganAudreysalesaudrey@company.com111-222-33-49
8COMPANY\user7JonesWilliamsaleswilliam@company.com111-222-33-50
9user8COMPANYRossBennettmanagementbennett@company.com111-222-33-51
10user9COMPANYGrovesEllamanagementella@company.com111-222-33-52

Command line examples:

> stcsvsync -i userinfo.csv -t D -cu A -cnb B -cf "%D %C" -cd E -ct "%F, %G" -cpr "profile1"

For FIO* [--column-fio] we use formula "%D %C". Interpreted as follows: value from 4th column, space, value from 3rd column.

*Term "FIO" means "full name" - first name, middle name, last name.

Department [--column-department] we use column number E (which means column 5). Formula "%E" will give same result.

Contacts [--column-contacts] formula "%F, %G". Value from 6th column, comma, space, value from 7th column.

Profile [--column-contacts] constant "profile1"

Output:

COMPANY\user6
        FIO:        Audrey Morgan
        Department: sales
        Contacts:   audrey@company.com, 111-222-33-49
        Profile:    profile1
COMPANY\user8
        FIO:        Bennett Ross
        Department: management
        Contacts:   bennett@company.com, 111-222-33-51
        Profile:    profile1
COMPANY\user9
        FIO:        Ella Groves
        Department: management
        Contacts:   ella@company.com, 111-222-33-52
        Profile:    profile1
COMPANY\user3
        FIO:        Harry Harrison
        Department: it
        Contacts:   harry@company.com, 111-222-33-46
        Profile:    profile1
COMPANY\user2
        FIO:        Jane White
        Department: it
        Contacts:   jane@company.com, 111-222-33-45
        Profile:    profile1
COMPANY\user1
        FIO:        John Smith
        Department: it
        Contacts:   john@company.com, 111-222-33-44
        Profile:    profile1
COMPANY\user5
        FIO:        Miles Davis
        Department: sales
        Contacts:   miles@company.com, 111-222-33-48
        Profile:    profile1
COMPANY\user4
        FIO:        Oscar Robbins
        Department: management
        Contacts:   oscar@company.com, 111-222-33-47
        Profile:    profile1
COMPANY\user7
        FIO:        William Jones
        Department: sales
        Contacts:   william@company.com, 111-222-33-50
        Profile:    profile1


Vacations and sick/leave

(see referenced topic at "Global settings" here)

ATTENTION target SQL-script will delete all from database table with info about vacations and sick/leave days and creates new records provided by .csv table.

Table vacations.csv

ABCD
1userbeginendreason
2DOMAIN\j.smith14.01.20241
3DOMAIN\j.smith15.01.20241
4DOMAIN\j.smith16.01.20241
5DOMAIN\j.smith17.01.20241
6DOMAIN\j.smith19.01.20241
7DOMAIN\j.smith20.01.20241
8DOMAIN\j.smith21.01.20241
9DOMAIN\j.smith25.01.202430.01.20241
10DOMAIN\w.johnes01.02.202417.02.20242
11DOMAIN\robbins28.02.202412.02.20243
12DOMAIN\j.smith29.01.202412.02.20241
13DOMAIN\j.smith07.02.20241
14DOMAIN\j.smith09.02.20241
15DOMAIN\j.smith07.01.202415.01.20241

Command line example:

> stcsvsync -i vacations.csv -t V -cu 1 -cvb 2 -cve 3 -cvr 4
DOMAIN\j.smith:  [2024-01-07 (1) 2024-01-17] [2024-01-19 (1) 2024-01-21] [2024-01-25 (1) 2024-02-12]
DOMAIN\w.johnes:  [2024-02-01 (2) 2024-02-17]
DOMAIN\robbins:  [2024-02-12 (3) 2024-02-28]

DOMAIN\username [--column-user], period begin date [--column-vacation-begin] are mandatory!

Period end date [--column-vacation-end] can be omited (will mean one-day leave)

Reason [--column-vacation-reason] must be integer. If omited or can't be reinterpreted as integer - will be zero.

Date can be in one of following: dd.mm.yyyy, dd/mm/yyyy, dd-mm-yyyy, yyyy-mm-dd, yyyymmdd. (Here: dd - day of month [1..31], mm - month number [1..12], yyyy - year in 4 digit form)

NOTE: any cases of duplicate dates or overlapping periods will be resolved.



Running SQL-scripts

You can run scripts in any familiar way, if you have one.
NOTE: don't forget to include the database name (stkh).

Example for MSSQL-tool sqlcmd:

> sqlcmd -d stkh -i script.sql -o output.txt -U dbadmin -P "*******"
> sqlcmd -d stkh -i script.sql -o output.txt
Example for PGSQL-tool psql:
> psql -d stkh -f script.sql -o output.txt -U postgres

ATTENTION! In case of synchronization of Managers (Subordination), after executing SQL-script you have to execute "Database configuration utility" (it will add new logins for Managers and assign them rights).

© Scopd