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:
Please log in to answer
Posted by:
gwir
7 years ago
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