Operating System - HP-UX
1847245 Members
2778 Online
110263 Solutions
New Discussion

"mesg n" and /etc/profile

 
James A. Donovan
Honored Contributor

"mesg n" and /etc/profile

Anyone know the correct way to test whether a login is an "initial connection" or a "su -"?

I set "mesg n" in my /etc/profile, and I want to get rid of the "mesg: cannot change mode" message I get every time I use "su - username" when switching.
Remember, wherever you go, there you are...
5 REPLIES 5
Steven E. Protter
Exalted Contributor

Re: "mesg n" and /etc/profile

Shalom,

I would think some variation of the who command will do it.

Also, there is an sulog that can be used to match against current sessions plus some evidence in the syslog itself.

This message is a good thing btw, not a bad. It shows that you don't permit terminal sessions to change settings on the fly. It prevents hacks.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
James A. Donovan
Honored Contributor

Re: "mesg n" and /etc/profile

...just figured out a way....man page for su pointed the way....

[ `echo ${0}` != "-su" ] && mesg n


this works for me, as all the users on my systems are only allowed to use /usr/bin/sh as their default shell.....
Remember, wherever you go, there you are...
James A. Donovan
Honored Contributor

Re: "mesg n" and /etc/profile

...just figured out a way....man page for su pointed the way....

[ `echo ${0}` != "-su" ] && mesg n


this works for me, as all the users on my systems are only allowed to use /usr/bin/sh as their default shell.....
Remember, wherever you go, there you are...
spex
Honored Contributor

Re: "mesg n" and /etc/profile

Hi James,

'who am i' returns real uid, while 'whoami' returns effective uid, so:

if [ "$(who am i)x" == "$(whoami)x" ];
then
# no su
else
# su
fi

PCS
spex
Honored Contributor

Re: "mesg n" and /etc/profile

I wasn't at a terminal when I wrote my last response. The conditional should be:

if [ "$(who am i | awk '{print $1}')x" = "$(whoami)x" ];
then
# no su
else
# su
fi

PCS