I don't know if someone might be interested but I leave it here also for my own reference:
I modified the line ssh root@$pbs_ip_address "poweroff < /dev/null" of @barrymossel to check first if there are other pending jobs on the PBS:
ssh root@$pbs_ip_address 'while [[ $(proxmox-backup-manager...