The Situation

We're running a headless Ubuntu 14.10 Server to fulfill various needs and tests. I was experimenting with changing the MOTD for SSH sessions via /etc/update-motd.d/ so as to display necessary information dynamically.

The problem I'm having is that almost any attempt to invoke a Python script to display the dynamic data doesn't work unless I include the script in this directory. It will recognize that the "remote" file can be executed but it does not display any output. I've done quite a bit of testing to figure it out on my own but — alas! — no success. I've become quite curious as to why it behaves like this.

Everything I have tested and discovered

I've created a global persistent environment variable that acts as a shortcut to our script /srv/hack.chat/WOTD. Typing $CHAT in a shell will print out the generated word. The contents of this file is dynamically erased and overwritten with new code each day. This is only because I'm picking my words from the american-english dictionary which include quote marks, thereby requiring an escape (\) to prevent errors.

I began changing the MOTD with a file named 00-linuxbox that created a static static message and ASCII "art" image. Near the end of the file it called /srv/hack.chat/WOTD. Once this script was called the rest of the code in 00-linuxbox would then be ignored. I tried many different ways to get it to work:

# Method 1: Use shortcut. Runs but no output to screen unless manually invoked

# Method 2: Exec. Bad practice. Immediately stops and runs command; remaing code is ignored
exec $CHAT

# Method 3: "Use this, not exec." Does not run at SSH MOTD.
#                                 Works when manually invoked afterwards.
if [ -x "$CHAT" ]; then

# Method 4: Call directly. Always runs but never shows any output, even if manually invoked
if [ -x "/etc/hack.chat/WOTD" ]; then

I did try to call on the script in a separate MOTD file to see if it would act any different but there was no change in behavior. The only time I've had success was when I cloned the script into the /etc/update-motd.d/ folder. This has left me a little confused.

To clarify what my question is:

MOTD will display any output from a Python script in /etc/update-motd.d/. It will not display any output from a Python script that is called from a MOTD shell script. What causes this behavior? I'm really curious to know.

  • I'm running into the exact same problem, but with a ruby script. Did you ever solve this? May 5, 2018 at 6:14
  • I did not. It’s been so long since I wrote this question that I’m afraid I may not be able to look into it again May 6, 2018 at 17:04
  • Thanks for the response nonetheless. I've temporarily solved the problem by making the file within the update-motd.d directory a symlink directly to the executable. May 6, 2018 at 19:35

1 Answer 1


It's most likely that the CHAT variable is not defined in the environment the motd scripts are being run; it's local to your shell process, not globally set. If you start a new shell session, you should observe that the variable is not available.

By default, the shell substitutes undefined variables as empty, so the line $CHAT is treated as empty, a no-op.

#4 probably doesn't work because the path specified is incorrect: you're looking for the file at /etc/hack.chat/WOTD, but the file is not there, but at /srv/hack.chat/WOTD. You don't even get an error message because your script first checks that /etc/hack.chat/WOTD is executable, which it isn't because there isn't a file at that path, and doesn't try to run it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .