Please help with a shell script to save a file locally

I’m trying to create a script that’ll save something to a file. I’m banging my head against the wall here, I tried this in a million different variations and I can’t understand why this is not working.

In configuration.yaml I have:

shell_command:
    save_pdf: echo "{{pdf_data}}" | base64 -d > /config/www/temp/{{file_name}}

In developer mode I try:

service: shell_command.save_pdf
data:
  pdf_data: JVBERi0xLjcKJcfs
  file_name: document5.pdf

The file isn’t being created. This must be such a stupid mistake, what am I doing wrong here?

Thanks!

The docs say that if you use templates in your command, then the command runs with more restrictions. Importantly for what you’re trying to do: pipes are not allowed.

To get around this for your example, create a shell script and save it somewhere like /config/shellscripts/savepdf.sh. The contents would be something like:

echo $1 | base64 -d > /config/www/temp/$2

Don’t forget to chmod it so that it’s executable.

Then your config would be:

shell_command:
  save_pdf: /config/shellscript/savepdf.sh {{pdf_data}} {{file_name}}

Thank you!