Newbie Need help with making a global profile change in AIX5.3

Right now I have to make a change on our AIX5.3 server that will add a couple of lines to everyone's profile. Please note I'm a Winodws ADMIn and not a AX person.

-Is there a default file I can update to make this addition to all users profiles?
-If so how can I do this?
LVL 20
compdigit44Asked:
Who is Participating?
 
woolmilkporcCommented:
Yes, but that's not cp, it's
cat file1 >> file2
where file1 is the file to be appended to file2
VERY IMPORTANT - Use '>>' to append!  ('>' alone will overwrite!)
Lets say file1 contains

newtextnewtextnewtext
newtextnewtextnewtext
newtextnewtextnewtext  
and file2 contains

OLDTEXTOLDTEXTOLDTEXT
OLDTEXTOLDTEXTOLDTEXT
OLDTEXTOLDTEXTOLDTEXT  
file2 will contain after the 'cat' operation -

OLDTEXTOLDTEXTOLDTEXT
OLDTEXTOLDTEXTOLDTEXT
OLDTEXTOLDTEXTOLDTEXT  
newtextnewtextnewtext
newtextnewtextnewtext
newtextnewtextnewtext    
 
wmp
 
0
 
woolmilkporcCommented:
Hi compdigit44,
nice to meet you again.
There is /etc/profile which is valid for all users.
Note that definitions of variables done here will be overridden by settings in the individual user's profile, unless set 'readonly'.
Edit this file with a text editor of your choice (as root) and test it carefully, as commands entered here will be executed at every user's login.
One could develop other methods. If you don'tlike using /etc/profile, we could find an alternative.
HTH
 
wmp
 
 
0
 
compdigit44Author Commented:
Stupid how will if konw if the gloabel change is being applied t all users profiles?
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
woolmilkporcCommented:
Hi,
the change is not applied to user's profiles.
Instead, /etc/profile will be executed during each user's login,  before his/her own profile.
There are no stupid questions. There are stupid answers ... well, sometimes.
 
wmp
 
0
 
compdigit44Author Commented:
Ok ... I was just checking with our vendor who application runs on this server and they stated that I need to changed a setting both the /etcprole & all users existing .profile as well how do I update the .profie for all my users? I have over 50 users accounts
0
 
woolmilkporcCommented:
Well,
I can't understand why changes should be necessary in both places, but I guess I don't have to.

So, let's use a script which will add some lines at the end of each .profile.

There are, as always, two possibilities.

1) Update .profile of each and every user, including root etc.

Run the following script, after replacing 'line[n].to.add' by your desired new lines.
Note the \n between the lines. They are mandatory newline characters!

#!/bin/ksh
ADD="line1.to.add\nline2.to.add\nline3.to.add\n"
lsuser -a ALL | while read  user
 do
  echo $ADD >> ~$user/.profile
 done
exit
 

2) Update .profile of selected users

2a) issue lsuser -a ALL > /tmp/userlist
2b)
edit /tmp/userlist and delete userids whose profile you don't want to change (e.g.root)
2c)
Run the following script, after replacing 'line[n].to.add' by your desired new lines.
Note the \n between the lines. They are mandatory newline characters!

#!/bin/ksh
ADD="line1.to.add\nline2.to.add\nline3.to.add\n"
cat /tmp/userlist | while read  user
 do
  echo $ADD >> ~$user/.profile
 done
exit

Good luck!

wmp

0
 
compdigit44Author Commented:
NO other way to do this ??? SMITTY etc...
0
 
woolmilkporcCommented:
No.
 
 Only for new users, by editing /etc/security/.profile (the one a newly created user gets copied into his home).
 
 smitty can't change .profile, let alone bulk changes.

That's why the AIX people invented /etc/profile.

Of course you could use vi to change profiles one by one by hand.

Or create a file containing your lines, go to the respective user's homedir and do a 'cat [file] >> .profile'

Last resort:

In case every user should have exactly the same .profile, write one as a prototype and use the above method #2),
replacing
echo $ADD >> ~$user/.profile
by
cp -pT [prototype] ~$user/.profile
and remove the 'ADD=...' line.

Sorry, no other way!

wmp




0
 
woolmilkporcCommented:
... mistake, no -T option in AIX's cp, sorry. Use only 'cp -p ...' if you'd like to use the prototype method.
0
 
compdigit44Author Commented:
could I do somethng like this...
I'm very nervious about using the script...
Could I take a existing .profile and make the changes to it the some how "copy" this file and have it replace everyone's current .profile..

if so how would I do this?? the cp command maybe???
0
 
compdigit44Author Commented:
also I did under stand the script syntax posted before I would have to write all of this ????
0
 
woolmilkporcCommented:
1)

That's exactly what I wrote in # 23625455. I called it the prototype method.

As you said,
- take an existing .profile, make the appropriate changes
- store it in a convenient place, let's say /var/tmp/.profile (but that's your choice).    
- make sure it's executable by issuing 'chmod u+x   /var/tmp/.profile'
- then either copy it one by one, by issuing 'cp -p /var/tmp/.profile  /home/of/some_user/'
- and give appropriate ownership by issuing 'chown [some_user]:[some_users_group]  /home/of/some_user/.profile'

- or use a script like this (for ALL users)

#!/bin/ksh
lsuser -c -a pgrp ALL | grep -v "#" | tr  ":"  " " > /tmp/userlist
cat /tmp/userlist | while read  user group
do
 cp -p /var/tmp/.profile  ~$user/.profile
 chmod u+x ~$user/.profile
 chown $user:$group ~$user/.profile
 done
exit

 2)
Regarding syntax - there is nothing special in the scripts

#!/bin/ksh      
- calls the shell that will execute the script's body
lsuser -c -a pgrp ALL | grep -v "#" | tr  ":"  " " > /tmp/userlist
- lists all users and their groups, gets rid of headers (grep -v), translates colons (:) to spaces (tr) and puts them into a file
cat /tmp/userlist | while read  user group
- takes the file, extracts user and group and passes them pair by pair to a while loop under the name 'user' and 'group'
do    
- start of the loop
cp -p /var/tmp/.profile  ~$user/.profile    
- copy (cp) the customized .profile to the user's ($user) home (the tilde (~) designates a user's homedir)
chmod u+x ~$user/.profile  
- make the copied .profile executable (+x) for the user  
chown $user:$group ~$user/.profile
- set user ownership and group ownership of .profile to the appropriate user and his group
done
- end of the loop
exit
- end of the script
 
 
wmp
0
 
kishored2004Commented:
Dont you understand....just go ahead and do it...if you are a windows admin....do that job....
0
 
compdigit44Author Commented:
Again sorry for the stupid question but I am the SOLE admin at my small comany.

It it possible to copy one file to another but not have the content over write  the target file but amend the added content ??

If so how????

0
 
kishored2004Commented:
You can always add additonal content to a text file using >> as mentioned above.

Best is to make a copy of the previous profile and copy the new profile with the script

If you just want to append it....instead of doing a copy just cat the new profile to add it to the new profile with >>

cat newprofile >> /home/<user>/.profile
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.