Hello,
quite a while ago i used Cygwin to run sh/bash scripts as custom sensors for PRTG. My setup is similar to this kb https://helpdesk.paessler.com/en/support/solutions/articles/60017-custom-sensor-bash-script
Now i want to use the "Windows Subsystem for Linux" feature in Windows 10 instead of Cygwin. I made sure the PRTG service runs under the same user as i used to setup WLS (Ubuntu). I changed the batch file accordingly "'c:\cygwin64\bin\bash.exe -l -c" -> "'c:\windows\system32\bash.exe -l -c" and verified it's working by executing it in cmd terminal.
Unfortunately i only get an error message in PRTG (response not well formed) "Antwort nicht wohlgeformt: "(Der Befehl "C:\Windows\System32\bash.exe" ist entweder falsch geschrieben oder konnte nicht gefunden werden. ECHO ist ausgeschaltet (OFF). )" (Code: PE132)"
However. If i copy bash.exe into the EXE folder (Custom Sensors) and write the whole -l -c ... string as parameter into the sensor, it works.
Any idea? I could use it with direct bash.exe command, but it would be nice to be able to just specify the script with its parameters or path.
Article Comments
THX for the reply, but i think you misunderstood my "problem". I have no issue calling a program / scrip with additional parameters. It's just that running a batch scrip callung bash.exe fails while running bash.exe directly works. The issue with directly running bash.exe is that i have to provide more parameters that are the same for all custom script sensors.
Oct, 2018 - Permalink
Hi there,
Do you execute the custom script like this:
PRTG > .BAT File > bash.exe |
Or like this
PRTG > bash.exe |
At what point do you need to provide more parameters and what keeps you from providing these?
Best regards.
Oct, 2018 - Permalink
Hey Dariusz,
with Cygwin i used PRTG > -BAT File > bash.exe
I would like to keep it that way using WSL, but i only get the above mentioned error.
So currently i use PRTG > bash.exe
If i use PRTG > bash.exe i need to call it like that:
bash.exe -l -c "/usr/local/scripts/some_script.sh param-1 param-n"
If i can use PRTG > BAT File > bash.exe, i can solely focus on the actual scripts
bash.bat
some_script.sh param-1 param-n
Tha later also has the advantage that i can have installations that differ from each other (like script files in /usr/local/some_other_folder/same_script_name.sh, which is important if i want to move/copy sensors/devices to other probes (without the need of checking how scripts are executed at that particular remote probe)
I hope this is now clear enough :D
Oct, 2018 - Permalink
Hi there,
Most likely the reason for the error is, that the script is executed under the SYSTEM user and the directory where the batch starts is "C:\Windows\System32\". So in this case when you only call "bash.exe", the commandline expects this exe to be available in the very same directory. Could you check if the "bash.exe" is really present in the "C:\Windows\System32\" directory?
Best regards.
Oct, 2018 - Permalink
Hey Dariusz,
the PRTG service runs unser dedicated administrative user (not SYSTEM). I monitor Veeam Backup with a powershell script that needs to run as that specific user (for authentication purposes) and it works.
C:\Windows\System32\bash.exe does exist. In fact i copied it from there to the EXE folder in order to run it directly without the .bat file.
Oct, 2018 - Permalink
Hi there,
To check this, please add a File Sensor (https://www.paessler.com/manuals/prtg/file_sensor) under the Probe device and use the path "C:\Windows\System32\bash.exe". Does that File Sensor work?
Best regards.
Oct, 2018 - Permalink
Hey Dariusz,
thank you for that suggestion. I think i found the problem, maybe, kinda :D
The File Sensor returned "Impersonation was denied (code: PE180)" which seems to be related to a bug in PRTG presented in this thread: https://helpdesk.paessler.com/en/support/solutions/articles/79162-impersonation-was-denied-code:-pe180
According to this thread it should befixed around May Quote: "There will be a bug fix in version 18.x.40. The release is planned for mid-May." Maybe it hasn't ben fixed yet?
I made a workaround by pointing to the bash.exe in the Custom Sensors\EXE folder (c:\PROGRA2\PRTGNE1\CUSTOM1\EXE\bash.exe). And it works :)
Oct, 2018 - Permalink
Hi there,
I have forgotten that you should add valid Windows Credentials into the device settings that are also available on the Core Server itself, might that be the case?
Best regards.
Oct, 2018 - Permalink
Hi there,
When you use the EXE/Script or EXE/Script Advanced Sensor, you are able to submit any parameters you want:
https://www.paessler.com/manuals/prtg/exe_script_sensor
https://www.paessler.com/manuals/prtg/exe_script_advanced_sensor
Have you tried that?
Best regards.
Oct, 2018 - Permalink