Operating System - HP-UX
1754359 Members
4771 Online
108813 Solutions
New Discussion юеВ

/etc/profile not executed for login shell other than sh, ksh, ...

 
Tony Chiu
Advisor

/etc/profile not executed for login shell other than sh, ksh, ...

The /etc/profile is not executed when my login shell is a shell script, eg. /home/user/menu.sh. I have the same script running well on other severs but dont run on this newly installed server.

I've checked the /etc/profile that can be run if the login shell is set to /usr/bin/ksh. Am I missing some configuration parms?

Thanks in advance,
Tony.
4 REPLIES 4
Dan Hetzel
Honored Contributor

Re: /etc/profile not executed for login shell other than sh, ksh, ...

Hi Tony,

It's normal as the /etc/profile will only run when the shell is an interactive login shell.
The shell started by your script isn't eiter interactive or a login shell.

You may force the reading of /etc/profile in your script by 'sourcing' the file, i.e. adding the following line:
. /etc/profile
close to the beginning of the file.

Best regards,

Dan
Everybody knows at least one thing worth sharing -- mailto:dan.hetzel@wildcroft.com
Tony Chiu
Advisor

Re: /etc/profile not executed for login shell other than sh, ksh, ...

Thanks Dan,

The method do work, but I wonder why other servers can run the same script without this modification. Am I missing some parms?

Tony.
Dan Hetzel
Honored Contributor

Re: /etc/profile not executed for login shell other than sh, ksh, ...

Hi Tony,

I don't believe that you're missing any parameter...

This is normal behavior for the shell. Here is a small abstract of the sh-posix manpage:
Shell Invocation
If the shell is invoked by an exec*() system call and the first
character of argument zero (shell parameter 0) is dash (-), the shell
is assumed to be a login shell and commands are read first from
/etc/profile, then from either .profile in the current directory or
$HOME/.profile if either file exists, and finally from the file named
by performing parameter substitution on the value of the environment
parameter ENV, if the file exists. If the -s option is not present
and an arg is, a path search is performed on the first arg to
determine the name of the script to execute. When running sh with
arg, the script arg must have read permission and any setuid and
setgid settings will be ignored.

Instead of starting the script, you could try the following (in the passwd file):
/usr/bin/sh /path_to/scriptname

In that case, I guess that the shell should read the /etc/profile as well as the user's .profile

All the best

Dan
Everybody knows at least one thing worth sharing -- mailto:dan.hetzel@wildcroft.com
Gregory Fruth
Esteemed Contributor

Re: /etc/profile not executed for login shell other than sh, ksh, ...

Try adding your script shell's name to the file /etc/shells.
I suspect that on those servers where your script shell
works, it's been added to /etc/shells.

/etc/shells is used by the function getusershell(), and I believe
things like telnet, xdm, etc. use getusershell() during the
login process.

Good luck!