#!/bin/bash
# Commands to run on Proxmox node
# Copy everything after the "---" line and paste into SSH session

cat << 'PROXMOX_COMMANDS'
---
VMID=100
echo "=== Automated Cleanup for VM $VMID ==="
pkill -9 -f "task.*$VMID" 2>/dev/null && echo "✅ Killed task processes" || echo "ℹ️  No task processes"
pkill -9 -f "qm.*$VMID" 2>/dev/null && echo "✅ Killed qm processes" || echo "ℹ️  No qm processes"
sleep 2
rm -f /var/lock/qemu-server/lock-$VMID.conf && echo "✅ Removed lock file" || echo "⚠️  Lock removal failed"
echo ""
echo "=== Verification ==="
ps aux | grep -E "task.*$VMID|qm.*$VMID" | grep -v grep || echo "✅ No processes remaining"
ls -la /var/lock/qemu-server/lock-$VMID.conf 2>&1 | grep -q "No such file" && echo "✅ Lock file removed" || echo "⚠️  Lock still exists"
echo ""
echo "=== Unlocking ==="
qm unlock $VMID
echo ""
echo "=== Final Status ==="
qm status $VMID
---
PROXMOX_COMMANDS

echo ""
echo "Copy everything between the '---' lines above and paste into your Proxmox SSH session"

