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.
Hours:
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
cancel
Showing results for 
Search instead for 
Did you mean: 

Disable motd for "su" commands.

 
SOLVED
Go to solution
compiler
Frequent Advisor

Disable motd for "su" commands.


Hi.

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?

Thanks.
3 REPLIES
Avinash20
Honored Contributor

Re: Disable motd for "su" commands.

http://forums11.itrc.hp.com/service/forums/questionanswer.do?threadId=1246203
"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
Solution

Re: Disable motd for "su" commands.

Hi:

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'.

Thus:

# cat myvars
#!/usr/bin/sh
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.

Regards!

...JRF...