I am looking to export an array from my heroku console into a local CSV file.
In my current situation, I have a daily rake task which looks for tweets talking about my a
I tried with the following steps with the new heroku console.I was able to get the logs.
open heroku console and execute commands.
when you are done type ctrl + d.
Terminal logs are saved in output.txt file.
You can run Ruby on your Heroku instance:
echo 'p User.first' | heroku run --no-tty 'ruby -W0 -r ./config/environment' > output.txt
This will print the first user to the output.txt
file.
Also you can run a local script on Heroku by piping it to the stdin.
cat my_script.rb | heroku run --no-tty 'ruby -W0 -r ./config/environment' > output.txt
Note that it's possible that you'll get some unwanted text (like warnings) that will appear at the beginning of the output.txt
file. You will have to trim it manually or by using a trimming command such as:
tail -n +4 -f
that will not print the first 4 lines.
Here is the full example:
cat my_script.rb | heroku run --no-tty 'ruby -W0 -r ./config/environment' | tail -n +4 -f > output.txt
I tried using Tee as suggested and also got stuck at
Running `console` attached to terminal... up, run.4165
I ended up running an SSH shell to localhost and then piped it through tee.
$ ssh localhost | tee output.txt
$ heroku run console
Might not be the best solution, but it worked for me.
I'd use Taps to export the db to your local machine, then operate on it there: https://devcenter.heroku.com/articles/taps