Running fortune in a Python virtualenv

I learned on reddit the other day about the sudo “insults” capability where it throws shade at you when you mistype the password. I configured it everywhere I could, but I wanted more, so I came across cowsay and fortune.

$ fortune | cowsay
/ SHIFT TO THE LEFT! SHIFT TO THE RIGHT! \
\ POP UP, PUSH DOWN, BYTE, BYTE, BYTE!   /
 ----------------------------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

Needless to say… wow.

Anyway so I wanted to get fortune going in my home-automation setup using home-assistant (which is running in a virtualenv) as a quote-of-the-day kind of thing but I kept running into trouble! My setup was:

sensor:
 - platform: command_line
    command: "fortune -a -s"
    scan_interval: 600
    name: quote

But I kept getting:

subprocess.CalledProcessError: Command 'fortune -a -s' returned non-zero exit status 127

Ugh!

It took me literally forever to realize that the package comes with two utilities that go in /usr/bin: unstr and strfile. These weren’t being found because the virtualenv’s bin folder was taking precedence. Two symlinks later, and I’m up and running!

lrwxrwxrwx 1 hass nogroup      14 Jan 21 22:21 unstr -> /usr/bin/unstr
lrwxrwxrwx 1 hass nogroup      16 Jan 21 22:07 strfile -> /usr/bin/strfile

Hope someone else finds this useful.

Leave a Reply

Your email address will not be published. Required fields are marked *