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
$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 $CHAT # 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 $CHAT fi # Method 4: Call directly. Always runs but never shows any output, even if manually invoked if [ -x "/etc/hack.chat/WOTD" ]; then /etc/hack.chat/WOTD fi
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.