Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2009-02-12
15
Medium Priority
?
455 Views
Last Modified: 2013-11-17
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?
0
Comment
Question by:compdigit44
  • 7
  • 6
  • 2
15 Comments
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 23621903
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
 
LVL 20

Author Comment

by:compdigit44
ID: 23623080
Stupid how will if konw if the gloabel change is being applied t all users profiles?
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 23623167
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 20

Author Comment

by:compdigit44
ID: 23624240
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
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 23624992
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
 
LVL 20

Author Comment

by:compdigit44
ID: 23625089
NO other way to do this ??? SMITTY etc...
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 23625455
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
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 23626942
... mistake, no -T option in AIX's cp, sorry. Use only 'cp -p ...' if you'd like to use the prototype method.
0
 
LVL 20

Author Comment

by:compdigit44
ID: 23631752
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
 
LVL 20

Author Comment

by:compdigit44
ID: 23631769
also I did under stand the script syntax posted before I would have to write all of this ????
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 23632050
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
 
LVL 2

Expert Comment

by:kishored2004
ID: 23647345
Dont you understand....just go ahead and do it...if you are a windows admin....do that job....
0
 
LVL 20

Author Comment

by:compdigit44
ID: 23660985
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
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 2000 total points
ID: 23661342
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
 
LVL 2

Expert Comment

by:kishored2004
ID: 23667375
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses
Course of the Month14 days, 17 hours left to enroll

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question