Run a multiline script remotely on a heroku app
To run a multiline script on heroku and capture it’s output, we can pipe the script to the rails runner via the heroku CLI, then redirect the stdout to a local file:
cat export.rb | heroku run "rails runner -" -a <APP ID> 2>/dev/null > data.json
Alternatively, in just a single script file using HEREDOC:
#! /usr/bin/env sh
heroku run "rails runner -" -a $APP_ID 2>/dev/null <<- BLOCK
puts Date.today
BLOCK