1828667 Members
1860 Online
109984 Solutions
New Discussion

scripting help...please

 
SOLVED
Go to solution
Peter Gillis
Super Advisor

scripting help...please

Hi,..hpux11.11v1, rp2470

My aim is to restrict login via startup script. This is what I have written into the /etc/profile:
if [ -r /etc/maintenance_mode ]
then
if [ $LOGNAME != root ]
echo " System down for maint "
then
exit 1
fi
fi

This is supposed to let only root login, and no other users (when attempting logging in with posix/bourne sh, but this is actually stopping ALL users including root from logging in.
Anyone see where I am going wrong. Help much appreciated and lotsa points floating around.
thanks heaps
Maria
6 REPLIES 6
Sanjay_6
Honored Contributor

Re: scripting help...please

Hi Maria,

Try this,

if [ -f /etc/maintenance_mode ]
then
if [ "$LOGNAME" != "root" ]
echo " System down for maint "
then
exit 1
fi
fi

hope this helps.

regds
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: scripting help...please

You are doing this the hard way. Edit /etc/default/security and add this line:
NOLOGIN=1


Now, when the file /etc/nologin exists only root can login; all other users receive a message from login that they are not allowed to login.

When maintenance mode is finished, simply remove or rename /etc/nologin. You don't need to do any scripting because login will handle it for you.
If it ain't broke, I can fix that.
Sanjay_6
Honored Contributor

Re: scripting help...please

hi,

Sorry about the previous post.

try this,

if [ -f /etc/maintenance_mode ]
then
if [ "$LOGNAME" != "root" ]
then
echo " System down for maint "
exit 1
fi
fi

Hope this helps.

Regds
Peter Gillis
Super Advisor

Re: scripting help...please

Sanjay,
thanks for quick reply.Unfortuneately I get exactly the same result....any more suggestions???
thanks, Maria
Rodney Hills
Honored Contributor

Re: scripting help...please

Your script has an error

if [ $LOGNAME != root ]
echo " System down for maint "
then

You should have this instead-

if [ $LOGNAME != root ]
then
echo " System down for maint "

"then" should be right after the "if"

HTH

-- Rod Hills
There be dragons...
Peter Gillis
Super Advisor

Re: scripting help...please

Thanks all.
I have tested both methods, and they are working for us.
with the /etc/profile script I had to also put the spaces between the [ and " , then all worked ok.
Thanks Clay, for the nologin info - this appears to be the way to go for notifying ( and kicking off) all types of shell users.
Maria.