/build/static/layout/Breadcrumb_cap_w.png

Scripting Question


Set an environnent variable from a label

10/06/2017 726 views
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.


Answer Summary:
0 Comments   [ + ] Show comments

Comments


Answer Chosen by the Author

1
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 !

Answered 10/13/2017 by: gwir
Brown Belt

All Answers

0
You could definitely do this with a script, but you might need a script per label. 
Answered 10/09/2017 by: chucksteel
Red Belt

 
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