v10.70 (build: Mar 4 2025)

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, G - Group Settings, H - Company structure, M - Meetings, P - PACS, 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
short full conversion type description
-h --help show usage
-i --input input file name
-o --output output file name
-of --output-format Output format: [MSSQL | PGSQL | TEXT] default: TEXT
-t --type Conversion type: D | G | H | M | P | S | V (Dossier, Group Settings, Hierarchy, Meetings, PACS, Subordination, Vacation)
-ns --no-sort [all] disable sorting before output
-tt --template [all] produce .csv template for provided conversion type
-hl --header-lines [all] number of lines represents header in .csv file [0..] default: 1
-dnb --domain-netbios [all] NB_domain in NETBIOS format. Applies when NB_column is omitted
-dfq --domain-fqdn [GH] Domain name (FQ_domain) FQDN format. Applies when FQ_domain is omitted
-ci --column-id [GHS] id column number
-cp --column-parent [HS] parent column number
-cn --column-name [H] name column number
-cu --column-user [all] user column number
-cc --column-computer [GH] computer column number
-cnb --column-domain-netbios [all] NB_domain column number
-cfq --column-domain-fqdn [GH] 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-value-begin [MPV] begin date column number
-cve --column-value-end [MPV] end date column number
-cvr --column-value-reason [MV] 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 table produced structure
Table example.csv
A B C D E F G H
1 id parent name user netbios_domain computer fqdn_domain boss
2 1 1 Company
3 2 1 Department 1
4 3 1 Department 2
5 4 2 Sub department 1.1
6 5 1 Sub department 1.2
7 6 5 Sub department 1.2.1 user1 COMPANY computer1 company.com yes
8 6 5 Sub department 1.2.1 user2 COMPANY computer2 company.com
9 6 5 Sub department 1.2.1 user3 COMPANY computer3 company.com
10 5 user4 COMPANY computer4 company.com
11 4 user5 COMPANY computer5 company.com yes
12 4 user6 COMPANY computer6 company.com
13 1 COMPANY\user7 computer7.company.com
14 2 user8 COMPANY computer8 company.com yes
15 3 user9 COMPANY computer9 company.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

A B C D E F G
1 user netbios_domain lastname firstname department e-mail phone
2 user1 COMPANY Smith John it john@company.com 111-222-33-44
3 user2 COMPANY White Jane it jane@company.com 111-222-33-45
4 user3 COMPANY Harrison Harry it harry@company.com 111-222-33-46
5 user4 COMPANY Robbins Oscar management oscar@company.com 111-222-33-47
6 user5 COMPANY Davis Miles sales miles@company.com 111-222-33-48
7 user6 COMPANY Morgan Audrey sales audrey@company.com 111-222-33-49
8 COMPANY\user7 Jones William sales william@company.com 111-222-33-50
9 user8 COMPANY Ross Bennett management bennett@company.com 111-222-33-51
10 user9 COMPANY Groves Ella management ella@company.com 111-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

A B C D
1 user begin end reason
2 DOMAIN\j.smith 14.01.2024 1
3 DOMAIN\j.smith 15.01.2024 1
4 DOMAIN\j.smith 16.01.2024 1
5 DOMAIN\j.smith 17.01.2024 1
6 DOMAIN\j.smith 19.01.2024 1
7 DOMAIN\j.smith 20.01.2024 1
8 DOMAIN\j.smith 21.01.2024 1
9 DOMAIN\j.smith 25.01.2024 30.01.2024 1
10 DOMAIN\w.johnes 01.02.2024 17.02.2024 2
11 DOMAIN\robbins 28.02.2024 12.02.2024 3
12 DOMAIN\j.smith 29.01.2024 12.02.2024 1
13 DOMAIN\j.smith 07.02.2024 1
14 DOMAIN\j.smith 09.02.2024 1
15 DOMAIN\j.smith 07.01.2024 15.01.2024 1

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-value-begin] are mandatory!

Period end date [--column-value-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.



Import records from Physical Access Control System (PACS).

ATTENTION target SQL-script will NOT delete any PACS data, as far as sequential imports are supposed. In case of errors or need to repeat import of last records - contact DB administrator, make sure data to delete to contains current period and current users only!

Table pacs.csv

A B C
1 user entry exit
2 DOMAIN\j.smith 15.01.2024 09:00:00 15.01.2024 18:00:00
3 DOMAIN\j.smith 16.01.2024 09:00:00 16.01.2024 18:00:00
4 DOMAIN\j.smith 17.01.2024 17.01.2024 18:00:00
5 DOMAIN\w.johnes 22.01.2024 08:00 22.01.2024 17:00
6 DOMAIN\robbins 22.01.2024 08:00 22.01.2024 17:00
7 DOMAIN\j.smith 21.01.2024 09:00 21.01.2024 18:00:00

Command line example:

> stcsvsync -i pacs.csv -t P -cu 1 -cvb 2 -cve 3
DOMAIN\j.smith:
        [2024-01-15 09:00:00 - 2024-01-15 18:00:00] 9h
        [2024-01-16 09:00:00 - 2024-01-16 18:00:00] 9h
        [2024-01-17 00:00:00 - 2024-01-17 18:00:00] 18h
        [2024-01-21 09:00:00 - 2024-01-21 18:00:00] 9h
        
DOMAIN\w.johnes:
        [2024-01-22 08:00:00 - 2024-01-22 17:00:00] 9h
        
DOMAIN\robbins:
        [2024-01-22 08:00:00 - 2024-01-22 17:00:00] 9h

DOMAIN\username [--column-user], datetime begin (entry) [--column-value-begin], datetime end (exit) [--column-value-end] are mandatory!



Assigning settings profiles to users and computers (GroupSettings)

(see referenced topic at "Global settings" here)

Settings profile number must be set through id, use -ci with corresponding column number.

Table groupsettings.csv

A B C D E
1 user nb_domain computer fqdn_domain profile_id
2 DOMAIN\j.smith 8
3 k.anderson DOMAIN 9
4 laptop152 domain.local 12
5 w.jhones DOMAIN 10
6 DOMAIN\robbins 3
7 SERVER-FS3.domain.local 2
8 WSADF34RT domain.local 11

Command line example:

> stcsvsync -i example.csv -t G -cu A -cnb B -cc C -cfq D -ci E
8        DOMAIN\j.smith
9        DOMAIN\k.anderson
3        DOMAIN\robbins
10       DOMAIN\w.jhones
12       LAPTOP152.domain.local
2        SERVER-FS3.domain.local
11       WSADF34RT.domain.local


Meetings, appointments, interviews

Table meetings.csv

A B C D
1 user begin end reason
2 DOMAIN\j.smith 14.01.2024 12:00 14.01.2024 13:30 Daily meeting with Devs
8 DOMAIN\j.smith 21.01.2024 10:30 21.01.2024 12:00 Project N meeting
10 DOMAIN\w.johnes 01.02.2024 14:30 01.02.2024 15:00 unplanned
11 DOMAIN\robbins 28.02.2024 10:00 28.02.2024 10:15 job interview

Command line example:

> stcsvsync -i meetings.csv -t M -cu 1 -cvb 2 -cve 3 -cvr 4

Datetime can be in one of following: dd.mm.yyyy hh:mm[:ss], dd/mm/yyyy hh:mm[:ss], dd-mm-yyyy hh:mm[:ss], yyyy-mm-dd hh:mm[:ss], yyyymmdd hh:mm[:ss]. (Here: dd - day of month [1..31], mm - month number [1..12], yyyy - year in 4 digit form, hh - hours [0..23], mm - minutes [0..59])



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).

© KICKIDLER DLP