Ad Widget

Collapse

Agent2 UserParameter for PowerShell with quotes in -File paramter

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • testperson
    Junior Member
    • Oct 2020
    • 1

    #1

    Agent2 UserParameter for PowerShell with quotes in -File paramter

    Hi,

    with the C Agent there was no problem using the following UserParamter:
    Code:
    UserParameter=my.script,powershell.exe -NoLogo -NoProfile -Noninteractive -ExecutionPolicy Bypass -File "%ProgramFiles%\Zabbix Agent\Scripts\MyScript.ps1-Param1 "$1" -Param2 $2"
    With Agent2 (5.0.4 on Windows Server 2016) I'll get an error as soon as I put quotes around my path to the script.
    "Error processing -File" "C:\Program": Illegal character in the path. Enter a valid path for the -File parameter.
    Without quotes I'm getting an error because of the space in the path:
    Error processing file "C:\Program" because the file does not have the extension ".ps1". Provide the valid name of a Windows PowerShell script file and try again.
    When using a path without spaces or using the 8dot3 names it is working unless I put quotes around the path.
    Code:
    UserParameter=My.Script[*],powershell.exe -NoLogo -NoProfile -Noninteractive -ExecutionPolicy Bypass -File C:\PROGRA~1\ZABBIX~1\Scripts\MyScript.ps1 -Param1 "$1" -Param2 $2
    Do I need to mask/escape the quotes in my case or is it a bug in Agent2? Or is it a bad idea to put scripts in the Zabbix install directory or in a place with spaces in the path?

    Thanks
    Jan
    Last edited by testperson; 05-10-2020, 09:43.
  • tinsmith1
    Junior Member
    • Nov 2020
    • 3

    #2
    Hi!

    In *nix it's frowned upon to have spaces in paths, but in Windows, considering the default filesystem hiearchy.

    Go 1.7.1 on windows-amd64, Windows 10 latest. Consider a test project: src/github.com/calmh/wincmdtest/ main.go folder name/ test.bat main.go contents: package main import ( "fmt" "os/exec" "string...


    The issue is in Zabbix using exec.Command to execute userparameters. This should not be used as mentioned in this issue.

    I don't see any possible workaround other than using prerendered 8dot3 paths, Windows POS.

    Code:
    cmd /c for %A in ("%ProgramFiles%\Zabbix Agent 2\somescript.ps1") do @echo %~sA
    Here's a command to generate stupid paths that works with the agent2.

    Comment

    • zaicnupagadi
      Member
      Zabbix Certified SpecialistZabbix Certified Professional
      • Dec 2010
      • 73

      #3
      Originally posted by tinsmith1
      Hi!

      In *nix it's frowned upon to have spaces in paths, but in Windows, considering the default filesystem hiearchy.

      Go 1.7.1 on windows-amd64, Windows 10 latest. Consider a test project: src/github.com/calmh/wincmdtest/ main.go folder name/ test.bat main.go contents: package main import ( "fmt" "os/exec" "string...


      The issue is in Zabbix using exec.Command to execute userparameters. This should not be used as mentioned in this issue.

      I don't see any possible workaround other than using prerendered 8dot3 paths, Windows POS.

      Code:
      cmd /c for %A in ("%ProgramFiles%\Zabbix Agent 2\somescript.ps1") do @echo %~sA
      Here's a command to generate stupid paths that works with the agent2.
      Had this issue today - thanks!

      Comment

      Working...