Operating System - HP-UX
1752808 Members
6028 Online
108789 Solutions
New Discussion юеВ

/etc/profile VS /home/username/.profile

 
SOLVED
Go to solution
RiclyLeRoy
Frequent Advisor

/etc/profile VS /home/username/.profile

I need to print a specific message when all users logout, so I insert:

trap "specific msg" 0 into /etc/profile

I verified that every user has just set into userhome folder another trap command to capture 0 signal (exit from shell):
trap "echo 'logout'" 0

1- Can I force my trap command for all users whithout doing changes on every /home/username/.profile ?
2- Where can I set default "profile" for new users ?
3 REPLIES 3
Kapil Jha
Honored Contributor

Re: /etc/profile VS /home/username/.profile

before home/username/.profile /etc/profile file is executed for all user, and you can do whatever you want to do and this would be applicable to all users.

Then you can refine user setting with .profile.

Hope I got what u trying to ask.

BR,
Kapil+
I am in this small bowl, I wane see the real world......
Fabio Ettore
Honored Contributor
Solution

Re: /etc/profile VS /home/username/.profile

Hi,

1- Can I force my trap command for all users whithout doing changes on every /home/username/.profile ?

I think it's not possible, the sequence on login is:

- reading /etc/profile then $HOME/.profile.
If $HOME/.profile contains different settings from /etc/profile, they will be loaded for that user.


2- Where can I set default "profile" for new users ?

/etc/skel/.profile

Here you set all default settings that you want when adding new users.

HTH.

Best regards,
Fabio
WISH? IMPROVEMENT!
Bill Hassell
Honored Contributor

Re: /etc/profile VS /home/username/.profile

> 1- Can I force my trap command for all users whithout doing changes on every /home/username/.profile ?

No. Every .profile is under control of the individual user. The line:

trap "echo 'logout'" 0

has been part of both /etc/profile and also .profile for many years -- and it's useless.

> 2- Where can I set default "profile" for new users ?

As mentioned, all the setup files for a new user are in /etc/skel.

You'll have to edit every user's $HOME/.profile to remove the extraneous trap 0. Or you can use the attached script to comment all the .profile files in one command:

chgafile "trap \"echo logout" "## trap ... logout commented out" /home/*/.profile /etc/skel/.profile

Run without options, it will show the before and after lines but won't change anything. Rerun the command with chgafile -w and the changes will be made to the files (including the template file in /etc/skel)

FYI: chgafile is a very powerful tool to make a simple text change across many, many files at the same time.


Bill Hassell, sysadmin