Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Can I put shell commands in the /etc/motd login banner file? I have tried:

 $(uptime)

and

`uptime`

Is this possible?

share|improve this question

2 Answers 2

up vote 5 down vote accepted

/etc/motd is only read and not executed, so technically speaking, you cannot put shell commands in there.

However, it's possible to execute a shell script at login time that will have the same result. This is usually achieved by adapting the /etc/profile script that is executed each time a user logs in. 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.

share|improve this answer
    
it's not a common practise to use /etc/motd.sh –  coincoin Dec 20 '12 at 16:51
    
@EricDANNIELOU Yes, one can use whatever script name he/she wants. I just removed the common adjective that was not appropriate. Still, having it named this way makes it easy to spot and know what purpose it serves. –  Tonin Dec 20 '12 at 17:18
    
There seems to be a way of using cron to regularly replace the static motd message: md3v.com/create-a-linux-server-status-motd I think that this profile script seems to be a better way, less moving parts. –  CMCDragonkai May 30 at 1:42
1  
Putting output like a MOTD in your profile is likely to break sftp. –  Stuart P. Bentley Aug 17 at 20:54

Yes, it's possible... Sorta.

Look up creating a dynamic MOTD. This is an abbreviated form of this documented process.

share|improve this answer
    
Do I just need to add session optional pam_motd.so to /etc/pam.d/login then make /etc/motd executable? –  Justin Dec 19 '12 at 4:21
2  
We really do prefer that answers contain content not pointers to content. Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference. –  Iain Dec 19 '12 at 12:10
    
The dynamic MOTD link essentially says you can add commands which print a message to /etc/profile, so this is equivalent to Tonin's answer. –  Andre Holzner Apr 4 at 7:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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