Mike Slinn

Bash shell on a Heroku Dyno

Published 2013-02-27.
Time to read: 1 minutes.

This page is part of the posts collection, categorized under Git, Heroku.

Up to now most of my work with Heroku has been via the heroku command line client, and pushing builds to app instances to have them compiled and run. Recently, I've been messing around with the remote bash shell of my Heroku apps. To enter a remote shell, just type the following from the root directory of a git project that declares your Heroku app as a remote repository. This command uses the heroku client provided by the Heroku toolbelt:

Shell
$ heroku run bash

Upon login, you are placed into the root directory of your deployed app. Unfortunately, you do not have access to the table of mounted file systems and you cannot run sudo.

Shell
~ $ pwd
/app 
~ $ ls -alF total 64 drwx------ 10 u37570 37570 4096 Dec  1 01:07 ./ drwxr-xr-x 15 root   root  4096 Oct 31  2011 ../ -rwx------  1 u37570 37570  183 Dec  1 01:05 .gitignore* drwx------  3 u37570 37570 4096 Dec  1 01:05 .ivy2/ drwxrwxr-x  6 u37570 37570 4096 Dec  1 01:05 .jdk/ drwx------  4 u37570 37570 4096 Dec  1 01:08 .sbt_home/ -rw-------  1 u37570 37570   98 Dec  1 01:05 Procfile -rw-------  1 u37570 37570 3833 Dec  1 01:05 README.md drwx------  5 u37570 37570 4096 Dec  1 01:05 app/ drwx------  2 u37570 37570 4096 Dec  1 01:05 conf/ drwx------  5 u37570 37570 4096 Dec  1 01:06 project/ drwx------  5 u37570 37570 4096 Dec  1 01:05 public/ -rwx------  1 u37570 37570   27 Dec  1 01:05 system.properties* drwx------  6 u37570 37570 4096 Dec  1 01:08 target/

Discover total used file space (my slug uses 1.7 GB):

Shell
~ $ du -sh --exclude='/proc/*' /
du: cannot read directory `/lost+found': Permission denied
du: cannot read directory `/etc/ssl/private': Permission denied
1.7G / 

All your environment variables are available:

Shell
~ $ set
... miles of output ... 

ifconfig is not available, but the IP address of your dyno can be discovered this way:

Shell
~ $ tail -n 1 /etc/hosts
10.92.81.76 e3d315e6-4392-4f3a-b7ae-75438c469697 

You can run sbt, but this is a bad idea because the Ivy cache is held outside the dyno, and there is no way for you to clean it without using some voodoo.

Shell
~ $ sbt update
[info] Loading global plugins from /app/.sbt_home/.sbt/plugins
[info] Loading project definition from /app/project
[info] Set current project to blahblah (in build file:/app/)
[info] Updating {file:/app/}blahblah...
... miles of output ...
[info] Done updating.
[success] Total time: 6 s, completed Feb 28, 2013 4:40:21 AM 


* indicates a required field.

Please select the following to receive Mike Slinn’s newsletter:

You can unsubscribe at any time by clicking the link in the footer of emails.

Mike Slinn uses Mailchimp as his marketing platform. By clicking below to subscribe, you acknowledge that your information will be transferred to Mailchimp for processing. Learn more about Mailchimp’s privacy practices.