pct exec export var.

Xilmen

Active Member
Mar 30, 2017
26
0
41
33
Hello everyone,
I need to do an export of a varibale in a LXC centos containers. After a few tests I notice that the values it returns for this varibale is an empty field.

Here is the test that I made :

Code:
root@srv-proxmox:[~]:# pct exec 302 -- bash -c "TMP=hi; echo $TMP"

root@srv-proxmox:[~]:#


The command that I really want to pass is the one :

Code:
pct exec 302 -- bash -c "IP=$(echo 192.168.2.222 | sed 's/^.*\.\([^.]*\)$/\1/') ; sed -i '/; PTR Records/a'$IP'    IN    PTR  try1\.lan\. ; 192.168.2.222' /etc/named/zones/db.lan.inv"
 
that has nothing to do with pct. what you are actually passing to pct is the command
Code:
TMP=hi; echo
because your shell will expand all the variables inside the double quotes, and TMP is not set/empty in your shell. you need to use single quotes or escape the special characters like $:
Code:
# pct exec 100 -- bash -c 'TMP=hi; echo $TMP'
hi
Code:
# pct exec 100 -- bash -c "TMP=hi; echo \$TMP"
hi
 
ty a lot :)

my command :

Code:
pct exec 302 -- bash -c "IP=$(echo 192.168.2.222 | sed 's/^.*\.\([^.]*\)$/\1/') ; sed -i '/; PTR Records/a'\$IP'    IN    PTR  try1\.lan\. ; 192.168.2.222' /etc/named/zones/db.lan.inv"

work's fine !
 

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!