Escape Double Quotes Inside pct exec "cmd"

May 18, 2019
231
15
38
Varies
inside the container

Code:
$ bash /home/ubuntu/scripts/logsigmonitor.sh 1 | while read LOGLINE; do echo "${LOGLINE}"; done

continuously outputs the desired (filtered) log messages to the terminal. but on the host

Code:
/usr/sbin/pct exec 107 -- bash -c "bash /home/ubuntu/scripts/logsigmonitor.sh 1 | while read LOGLINE; do echo \"${LOGLINE}\"; done"

only outputs blank lines for each line the script inside the container prints.

how do i escape the quotes inside the bash cmd in the host?
 
Hi,

Are you tried double quotes inside single quotes like this example?

Bash:
pct exec 107 -- bash -c 'curl -I -k "https://10.0.0.1:8006"; id'
 
  • Like
Reactions: Proxygen
bash: -c: line 0: syntax error near unexpected token `;'

tried with single quotes around the cmd, and unescaped double quotes inside the cmd:

'bash /home/ubuntu/scripts/logsigmonitor.sh $var | while read LOGLINE; do; echo "${LOGLINE}"; done'

it might work if we didn't need $var inside the cmd. we need $var to be contained within double quotes for variable expansion.
 
Works with me

Bash:
pct exec 107 -- bash -c 'curl -I -k "https://10.0.0.1:8006"; 'x=10'; echo $x'

Output:

Code:
HTTP/1.1 501 method 'HEAD' not available

Cache-Control: max-age=0

Connection: close

Date: Wed, 27 May 2020 06:21:34 GMT

Pragma: no-cache

Server: pve-api-daemon/3.0

Expires: Wed, 27 May 2020 06:21:34 GMT


10
 
  • Like
Reactions: Proxygen
This works because $x is created inside the statement `pct exec 107 -- bash -c 'curl -I -k "https://10.0.0.1:8006"; 'x=10'; echo $x'`

This does not work: a variable is passed to the script (on the host) to expand when used inside the `pct exec` statement. it does not expand inside single quotes.
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!