Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't run a printf command #2

Closed
ilium007 opened this issue May 10, 2024 · 6 comments
Closed

Can't run a printf command #2

ilium007 opened this issue May 10, 2024 · 6 comments
Assignees
Labels
enhancement New feature or request

Comments

@ilium007
Copy link

ilium007 commented May 10, 2024

Not sure what is happening but when I run the following it errors.

root@pve01:~# cat /etc/proxmox_grapple.yml
production:
  job-start:
    script:
      - 'printf "$(date) PVE hook script start pve01 - $(pveversion)\n" | tee /mnt/ext_usb_01/pve01.log'

But works from command line:

root@pve01:~# printf "$(date) PVE hook script start pve01 - $(pveversion)\n" | tee /mnt/ext_usb_01/pve01.log

Error in the Proxmox backup console:

INFO: HOOK: /root/.local/bin/proxmox-grapple job-start
INFO: HOOK-ENV: vmtype=None; dumpdir=/mnt/ext_usb_01/dump; storeid=ext_usb_01; hostname=None; tarfile=None; logfile=None
INFO:     Running: printf "$(date) PVE hook script start pve01 - $(pveversion)\n" | tee /mnt/ext_usb_01/pve01.log
INFO:     "$(date)printf: warning: ignoring excess arguments, starting with 'PVE'
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale May 10, 2024
@github-actions github-actions bot locked and limited conversation to collaborators May 10, 2024
@lingfish lingfish reopened this May 10, 2024
Repository owner deleted a comment from github-actions bot May 10, 2024
Repository owner unlocked this conversation May 10, 2024
@lingfish
Copy link
Owner

So this one makes sense -- just like vzdump, grapple basically does a Python execvpe... exec's whatever you configure on the script lines. The key here is that it does not run a shell around your commands, so shell-specific things like pipes and command substitution/variable expansion obviously won't work.

My assumption had been that if a user wanted that, they'd configure grapple with something along the lines of bash -c "confusing_mess_with_single_and_double_quotes and_escaping"

I could look into a config option to turn on Popen's shell=True, but would be low on the list.

@lingfish lingfish added the enhancement New feature or request label May 10, 2024
@ilium007
Copy link
Author

All good. I'll have to find a different solution.

@lingfish
Copy link
Owner

You could put that/those lines into a shell script, with a shebang at the top, or yeah, wrap it in a sh/bash -c line.

@ilium007
Copy link
Author

That's were I started, a shell script with a shebang!

#!/bin/bash

PVE_NODE="$(hostname)"
LOG_FILE="/mnt/ext_usb_01/$PVE_NODE.log"

if [ "$1" == "job-start" ]; then
  printf "$(date) PVE hook script start ($PVE_NODE) - $(pveversion)\n" | tee $LOG_FILE
fi

if [ "$1" == "job-end" ]; then
  /usr/local/bin/autorestic -c /root/.autorestic.yml --restic-bin /usr/local/bin/restic backup --verbose --all 2>&1 | tee -a $LOG_FILE
fi

@lingfish
Copy link
Owner

Well, I've now implemented the shell option, hopefully this helps!

https://github.com/lingfish/proxmox-grapple/releases/tag/1.5.5

@lingfish lingfish self-assigned this May 17, 2024
@ilium007
Copy link
Author

I will give it a go. I got autorestic working in the standard shell script by including PATH=$PATH before calling autorestic (don't ask me why it works)

#!/bin/bash

PVE_NODE="$(hostname)"
LOG_FILE="/mnt/ext_usb_01/$PVE_NODE.log"
PATH=$PATH

if [ "$1" == "job-start" ]; then
  printf "$(date) PVE hook script start ($PVE_NODE) - $(pveversion)\n" | tee $LOG_FILE
fi

if [ "$1" == "job-end" ]; then
  /usr/local/bin/autorestic -c /root/.autorestic.yml --restic-bin /usr/local/bin/restic backup --verbose --all 2>&1 | tee -a $LOG_FILE
fi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants