I'd like to run a python script when people log in to the server. I thought editing /etc/motd would be the best approach, but since it's only readable file, that won't work.

I found pretty much identical post: Is it possible to put commands in /etc/motd?

What would be the best solution here? I'd like to run a script that shows the overview of the server, so the users would see the status immediately.

This was suggested A useful practice is to put the command you want to be executed in a script named /etc/motd.sh and call this script from /etc/profile, usually at about the end of it.

but received this comment Putting output like a MOTD in your profile is likely to break sftp.

Any solution will do. Thanks in advance

  • 1
    I did link that myself already in the post?:) – jester112358 May 22 '15 at 8:49

Actually it's better to use /etc/profile.d for this option. And source script there. It would display output on every login.

About the second problem and breakinf sftp. I did a little bit googling.

You can use:

Subsystem sftp /usr/lib/openssh/sftp-server

in your /etc/ssh/sshd_config.

Or add

if [ "$SSH_TTY" ]
   source .bashc_real

to your script which prints motd-like message. I get this answer from(Use .bashrc without breaking sftp).

| improve this answer | |

In Ubuntu/Debian, PAM module pam_motd supports that dynamic motd functionality, and supposedly it doesn't interfere with sftp. Unfortunately it's not well documented. You can instead consult update-motd manpage in Ubuntu.

On the Ubuntu systems you already have several scripts in /etc/update-motd.d/. They are live examples suitable for your own to start from.

Consider carefully about consuming certain resources on every login with dynamic motd. Read Best Practices section in update-motd manpage.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.