This wmic query (NODE, USER, PASS all desensitised)...
wmic /NODE:10.00.00.1 /LOCALE:MS_409 /PRIVILEGES:ENABLE /TRACE:OFF /INTERACTIVE:OFF /FAILFAST:OFF /USER:domain\my_user /PASSWORD:myPass! /OUTPUT:STDOUT /APPEND:STDOUT /AGGREGATE:ON class StdRegProv CALL EnumKey ^&H80000002,"Software\Microsoft\SystemCertificates\MY\Certificates"
^&H80000002 is the uint32 conversion of HKEY_LOCAL_MACHINE
... runs flawlessly in a CMD prompt in Windows. I can also run it in the context of a node package from my local windows machine with success, I'm going to assume this is because the wmic call is made specifically to the local machine (windows) where it is handled effortlessly. Returning to me a result containing what I require...
res.sNames [ 'BB731A3DD8F089A6D4E59AF9D706...' ]
I created a docker container running Alpine and node where I host an express application. I followed the instructions below to install WMIC on Linux...
https://askubuntu.com/questions/885407/installing-wmic-on-ubuntu-16-04-lts
This installed successfully.
Now when I run the exact same query from a bash prompt in Ubuntu either via my Node app or a direct command, I'm receiving this result:
Garne#MYCOMPUTERNAME MINGW64 ~
$ wmic.exe /NODE:10.00.00.1 /LOCALE:MS_409 /PRIVILEGES:ENABLE /TRACE:OFF /INTERACTIVE:OFF /FAILFAST:OFF /USER:domain\my_user /PASSWORD:myPass! /OUTPUT:STDOUT /APPEND:STDOUT /AGGREGATE:ON class StdRegProv CALL EnumKey ^&H80000002,"Software\Microsoft\SystemCertificates\MY\Certificates"
[1] 426
bash: H80000002,Software\Microsoft\SystemCertificates\MY\Certificates: No such file or directory
Garne#MYCOMPUTERNAME MINGW64 ~ $ ERROR: Description = Access is
denied.
I can't for the life of me work out whether this is due to a string formatting error in Linux vs Windows or whether Linux is running a different variant of wmic that isn't resolving my query correctly?
For anyone wondering, after hours of testing this with very obscure error messages. Make sure you escape absolutely everything in bash style not in a windows fashion.
Note:
\$ instead of ^&
Wrap USER value in ''
Wrap PASSWORD value in ''
References here:
https://manpages.debian.org/buster/bash/bash.1.en.html#QUOTING
$ wmic /NODE:10.23.0.11 /LOCALE:MS_409 /PRIVILEGES:ENABLE /TRACE:OFF /INTERACTIVE:OFF /FAILFAST:OFF /USER:'domain\my_user' /PASSWORD:'myPass!' /OUTPUT:STDOUT /APPEND:STDOUT /AGGREGATE:ON class StdRegProv CALL EnumKey \&H80000002,"Software\Microsoft\SystemCertificates\MY\Certificates"
Executing (StdRegProv)->EnumKey()
Method execution successful.
Out Parameters:
instance of __PARAMETERS
{
ReturnValue = 0;
sNames = {"BB731A3DD8F089A6D4E59AF9D70601F9CBB94A9D"};
};
Related
I am developing an executable with Python 3.7 on Windows 10.
My software needs to install 2 programs: the sdkmanager and the build-tools utilities.
My main issue is to use the environment variables freshly modified.
To install build-tools, I need first to install SDKmanager. When my code installs SDKManager, it is adding environment variables to make the program "sdkmanager.bat" available in the environment.
The first command my software is doing is "sdkmanager --list". When my program.exe run this command, it says "this program is not recognized and internal or external command". It is normal as my program.exe just changed the environment variable PATH and it needs to restart to use it.
So my program.exe start a new instance of program.exe. This 2nd program.exe detect the first program.exe and kill it in order to let only 1 program.exe running.
So this 2nd program.exe suppose to enjoy the new environment variable, but it is not the case.
I tried all the possible code to start new porgram.exe:
proc = subprocess.Popen("start myprogram.exe", shell=True,stdin=None, stdout=True, stderr=None, close_fds=True)
os.system('start cmd /c "myprogram.exe"')
proc = os.popen("start cmd /c myprogram.exe")
proc = subprocess.check_call(['myprogram.exe'], shell=True)
proc = subprocess.run(['myprogram.exe'])
ctypes.windll.shell32.ShellExecuteW(None, "runas", 'myprogram.exe', '', None, 1)
etc....
It didn't work. Each time my program can't run the command "sdkmanager --list" as it says "this program is not recognized and internal or external command".
What is weird is I am displaying the value of the environment variable PATH and I can see the path to the script sdkmanager.bat.
So I used different methods to propagate the new environment variables:
#Method 1
def RefreshEnvironment():
#https://gist.github.com/apetrone/5937002
HWND_BROADCAST = 0xFFFF
WM_SETTINGCHANGE = 0x001A
SMTO_ABORTIFHUNG = 0x0002
sParam = "Environment"
res1, res2 = win32gui.SendMessageTimeout( HWND_BROADCAST, WM_SETTINGCHANGE, 0, sParam, SMTO_ABORTIFHUNG, 100 )
bool_res=bool(res1)
if not res1:
logger.info(f"result: {bool_res} {res2} from SendMessageTimeout")
#Method 2
def RefreshEnvironment(timeout_ms=2000):
#https://programtalk.com/python-examples-amp/win32con.HWND_BROADCAST/
"""Broadcast a message to all top-level windows informing them that
an environment change has occurred. The message must be sent, not posted,
and times out after `timeout_ms` ms since some top-level windows handle this
badly. NB This is a static method.
"""
win32gui.SendMessageTimeout(
win32con.HWND_BROADCAST, win32con.WM_SETTINGCHANGE,
0, "Environment",
win32con.SMTO_ABORTIFHUNG, timeout_ms
)
But it didn't work.
What is very weird, is when I restart program.exe manually myself by double clicking on it, it works! program.exe recognized the command "sdkmanager --list" when I run the program myself whereas it doesn't if program.exe restart itself. I don't understand.
Does anyone already face this situation where your program has to restart to enjoy the environment variable?
My problem is I didn't understand well how the environment works with python.
In fact, there are 2 environments:
The environment of the machine.
The environment of python loaded when Python starts.
I was changing with success the environment of my machine, but Python was keeping its own environment in its memory. So even if everything was updated in the environment machine, Python was ignoring it, even after restarting the program.
I had to use the module os.environ to load my new environment variable in the Python environment in order to let Python enjoy these new environment variables.
Here is the code I use now which is working from my side:
# After I change the environment variable, I use my function 'GetEnvVarSys' to get the environment variable from Windows registry
ANDROID_HOME=GetEnvVarSys("ANDROID_HOME")
JAVA_HOME=GetEnvVarSys("JAVA_HOME")
PATH=GetEnvVarSys("PATH")
# then I pass them to Python os.environment
os.environ['ANDROID_HOME'] = ANDROID_HOME
os.environ['JAVA_HOME'] = JAVA_HOME
os.environ['PATH'] = PATH
I have a task to install Oracle 11g on a centOS 8 using VM (i'm new to linux / oracle).
I downloaded the Oracle files and unzipped them, then I tried to ./runInstaller but I get an error and this is the full terminal with error:
login as: admin
admin#192.168.163.129's password:
Activate the web console with: systemctl enable --now cockpit.socket
Last login: Thu May 21 09:26:48 2020 from 192.168.163.1
[admin#oracledb ~]$ cd Downloads
[admin#oracledb Downloads]$ cd database
[admin#oracledb database]$ ls
doc linux.x64_11gR2_database_1of2 response runInstaller stage
install linux.x64_11gR2_database_2of2 rpm sshsetup welcome.html
[admin#oracledb database]$ ./runInstaller
Starting Oracle Universal Installer...
Checking Temp space: must be greater than 120 MB. Actual 2027 MB Passed
Checking swap space: must be greater than 150 MB. Actual 1759 MB Passed
Checking monitor: must be configured to display at least 256 colors
>>> Could not execute auto check for display colors using command /usr/bin/xdpyinfo. Check if the DISPLAY variable is set. Failed <<<<
Some requirement checks failed. You must fulfill these requirements before
continuing with the installation,
Continue? (y/n) [n] y
>>> Ignoring required pre-requisite failures. Continuing...
Preparing to launch Oracle Universal Installer from /tmp/OraInstall2020-05-21_09-43-58AM. Please wait ...
DISPLAY not set. Please set the DISPLAY and try again.
Depending on the Unix Shell, you can use one of the following commands as examples to set the DISPLAY environment variable:
- For csh: % setenv DISPLAY 192.168.1.128:0.0
- For sh, ksh and bash: $ DISPLAY=192.168.1.128:0.0; export DISPLAY
Use the following command to see what shell is being used:
echo $SHELL
Use the following command to view the current DISPLAY environment variable setting:
echo $DISPLAY
- Make sure that client users are authorized to connect to the X Server.
To enable client users to access the X Server, open an xterm, dtterm or xconsole as the user that started the session and type the following command:
% xhost +
To test that the DISPLAY environment variable is set correctly, run a X11 based program that comes with the native operating system such as 'xclock':
% <full path to xclock.. see below>
If you are not able to run xclock successfully, please refer to your PC-X Server or OS vendor for further assistance.
Typical path for xclock: /usr/X11R6/bin/xclock
[admin#oracledb database]$
I am using putty and Xming but I still get this error.
Make sure your putty session is connecting with "x-11 port forwarding"
Be sure after you set this that you scroll back up to 'Session' and then 'save'
On Jenkins I'm using the Conditional BuildStep Plugin. Is there a way to have it run some build steps depending on whether or not the slave node it's running on is Windows vs. Linux?
You can use isUnix() function available in jenkins for identifying the OS type.
So you can use something like below inside your jenkinsfile under script block:-
if (isUnix()) {
sh 'ls -la'
} else {
bat 'dir'
}
To run commands only if the current server is Windows, use the Conditional BuildStep Plugin to check:
Strings match:
String 1: ${ENV,var="OS"}
String 2: Windows_NT
And to run commands only if the current server is Linux, check:
Strings match:
String 1: ${ENV,var="OS"}
String 2:
(Leaving String 2 blank.)
I am submitting a shell script on a remote host that in turn submits an R script, but the error R: command not found or Rscript: command not found (depending whether I tried R CMD BATCH or Rscript).
I have tried submitting in the following ways:
ssh <remote-host> exec $HOME/test_script.sh
ssh <remote-host> `sh $HOME/test_script.sh`
The script test_script.sh contains (have tried Rscript as well):
#!/bin/sh
Rscript --no-save --no-restore $HOME/greetme.R
exit 0
The script greetme.R contains only cat("Hello\n").
The reason I am getting flustered is that when I log into the remote-host and submit the original script with sh $HOME/test_script.sh, it runs as intended.
The system specs and R versions for both the local and remote hosts are identical:
> R.version
_
platform x86_64-unknown-linux-gnu
arch x86_64
os linux-gnu
system x86_64, linux-gnu
status
major 3
minor 1.0
year 2014
month 04
day 10
svn rev 65387
language R
version.string R version 3.1.0 (2014-04-10)
nickname Spring Dance
Why is Linux refusing to recognize the commands?
I would prefer solutions using R CMD BATCH or Rscript but if there are known workarounds using littler or %R_TERM% I would like to hear them too.
I used this related question as reference, as well as the documents referenced in the comments: R.exe, Rcmd.exe, Rscript.exe and Rterm.exe: what's the difference?
EDIT for solution:
As #merlin2011 suggested, once I specified the full path in the test_script.sh, everything worked as intended:
#!/bin/sh
/opt/R/bin/Rscript --no-save --no-restore $HOME/greetme.R
exit 0
I got the path also by the provided suggestion:
$ which Rscript
/opt/R/bin/Rscript
It appears that you have a PATH issue, where R is not on your PATH when you try to run the command through ssh.
If you specify the full path to R and Rscript on the remote host, it should resolve the problem.
If you are not sure what the full path is, try logging into the server and running which R to get the path.
Im trying to run sqlplus from user oracle in linux, but i only get the following error.
Error 6 initializing SQL*Plus
SP2-0667: Message file sp1<lang>.msb not found
SP2-0750: You may need to set ORACLE_HOME to your Oracle software directory
[ sqlplus ] completed with error code: 1
I have tried to run ./oracle_env.sh as user oracle and have tried it as user root as-well, but when I run the sqlplus / as sysdba command logged in as user oracle I get the above message.
Did I miss something, am I on completely the wrong track?
Here is a full output that I used/got.
`su - oracle
cd /u01/app/oracle/product/11.2.0/xe/bin
./oracle_env.sh
sqlplus / as sysdba`
If /u01/app/oracle/product/11.2.0/xe/bin/oracle_env.sh sets your ORACLE_HOME, and ORACLE_SID environment variables, you need to "source" it invoking it in the current environment) using the "dot" prefix:
. ./oracle_env.sh
In any case, looks like your environment variables (including LD_LIBRARY_PATH) may not be set correctly.