How do I display a logon banner when using a one-off dyno?

Issue

You want to display a logon banner message when running a one-off dyno.

Resolution

Heroku dynos run a .profile script during startup that can be used to display a logon banner.

The $DYNO environment variable can be used to determine the type of dyno that is running: both heroku run and heroku console will spin up one-off dynos with $DYNO set to something like run.1234. A simple regular expression at the start of the .profile script can check for this before displaying the banner message to the end-user using echo.

Here's an example:

#!/bin/bash
if [[ $DYNO =~ ^run\..*$ ]]
  then
    echo "Warning: access to this system is limited to authorized users."
fi

Ask on Stack Overflow

Engage with a community of passionate experts to get the answers you need

Ask on Stack Overflow

Heroku Support

Create a support ticket and our support experts will get back to you

Contact Heroku Support