Run a script residing in a container using 'pct exe'

psionic

Member
May 23, 2019
75
9
13
I have a script in a container that I want to execute when doing a backup.
If I manually execute the script from the node CLI using:
pct exe <id> -- ./script.sh
The script runs as expected.

The problem is when I put the exact same command in my hook script, I get an execution error:

INFO: Stop daemon for 4000 backup
INFO: lxc-attach: 4000: attach.c: lxc_attach_run_command: 1503 No such file or directory - Failed to exec "./stopmn.sh"
ERROR: Backup of VM 4000 failed - command '/root/backup-hook.sh backup-start stop 4000' failed: exit code 127
INFO: Failed at 2020-04-18 17:36:03
INFO: Backup job finished with errors
TASK ERROR: job errors


Any help with this would be appreciated,,,

Here is the hook script:

#!/bin/bash

if [ "$1" == "backup-start" ] && [ ${VMTYPE} == "lxc" ]; then
echo "Running pre backup guest update/upgrade for $3"
pct exec "$3" -- bash -c "apt-get update -y && apt-get upgrade -y"
echo "Running pre backup guest cleanup for $3"
pct exec "$3" -- bash -c "apt-get clean"
echo "Stop daemon for $3 backup"
pct exec "$3" -- ./stopmn.sh
fi
 

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!