HPE Community read-only access December 15, 2018
This is a maintenance upgrade. You will be able to read articles and posts, but not post or reply.
Dec 15, 4:00 am to 10:00 am UTC
Dec 14, 10:00 pm CST to Dec 15, 4:00 am CST
Dec 14, 8:00 pm PST to Dec 15, 2:00 am PST
System Administration
Showing results for 
Search instead for 
Did you mean: 

Disable motd for "su" commands.

Go to solution
Frequent Advisor

Disable motd for "su" commands.


I have some scripts that do:

su - user -c "command"

The problem is that the above shows the motd of the server, exactly like you were login in as "user".

I cannot redirect stdout nor stderr to /dev/null because I need the output of command execution.

Is there any way to "hide" motd message in this case while keeping it for standard logins?

Honored Contributor

Re: Disable motd for "su" commands.

"Light travels faster than sound. That's why some people appear bright until you hear them speak."

Re: Disable motd for "su" commands.

Only by removing that "-". You'll need to change your command to not depend on that user's .profile.

I'm not sure you want to fiddle with /etc/profile and use advanced AI technology to figure out whether su changed the name of users in your process tree.
James R. Ferguson
Acclaimed Contributor

Re: Disable motd for "su" commands.


Instead of doing 'su -' which causes the user's profile to be sourced (read), build a file of all the environmental variables you normally want when you login to that user. Then you can source that file as a part of the user's profile _AND_ when you perform a simple 'su'.


# cat myvars
export MYID=me

...now source this in the user's '.profile':

. ${HOME}/myvars

...and when you need to 'su' (for example):

# su jrf -c ". myvars;env|grep me;date"

NOTE carefully that to source you type a dot followed by whitespace, followed by the file to be sourced.