/build/static/layout/Breadcrumb_cap_w.png

Set an environnent variable from a label

Hello,

Is it possible to set an environment variable from a label? Our classroom are tag like this ens.<city>.<building>.<room> and it could be useful for us to set an environment variable like %KACE_LABEL%. Does any of you ever did it and how ?

Thank you.



0 Comments   [ + ] Show comments

Answers (2)

Answer Summary:
Posted by: gwir 7 years ago
Second Degree Brown Belt
1

Top Answer

I finaly found how to did it.

  • First you need a mysql client. I took this one https://dev.mysql.com/downloads/file/?id=471341
  • Extract it take copy the mysql.exe and mysql_config_editor.exe to your working directory.
  • With mysql_config_editor.exe create a crypted login file :
    mysql_config_editor.exe set --login-path=k1000 --host=k1000.kbox.com --user=R1 --password

    Now you have you credentials in %APPDATA%\MySQL\.mylogin.cnf

  • copy the .mylogin.cnf file in your working directory
  • now you can run this batch script :
    :: setting variables
    SET MY="%~dp0mysql.exe"
    SET SQL="%TEMP%\KACE_LABEL.sql"

    :: Building the query
    :: you can change the "Where" part to adapt it to your needs
    ECHO SELECT LABEL.NAME FROM LABEL LEFT JOIN MACHINE_LABEL_JT ON LABEL.ID = MACHINE_LABEL_JT.LABEL_ID LEFT JOIN MACHINE ON MACHINE_LABEL_JT.MACHINE_ID = MACHINE.ID WHERE MACHINE.NAME = '%COMPUTERNAME%' AND LABEL.NAME like '%%.%%.%%.%%' AND LABEL.NAME NOT LIKE '%%all'; > %SQL%

    :: Copying the credential file to the current user roaming profile
    MD "%APPDATA%\Mysql"
    copy "%~dp0.mylogin.cnf" "%APPDATA%\Mysql"

    :: running the query and store the label in
    %TEMP%\LABEL.TXT
    %MY% --login-path=k1000 -s -D ORG1 < %SQL% > %TEMP%\LABEL.TXT

    :: Setting the environement variable
    SETX KACE_LABEL /F %TEMP%\LABEL.TXT /A 0,0 /M

    :: deletion of the credential file
    rmdir /q /s "%APPDATA%\Mysql"
That's it !

Posted by: chucksteel 7 years ago
Red Belt
0
You could definitely do this with a script, but you might need a script per label. 
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ