I want to write a script that will update all our UNIX machines' hosts files and users. What we have is a UNIX server that serves a few UNIX machines. I want to be able to copy the hosts file and the user profiles and login info from the server to all the other machines(instead of updating all the machines one by one).
I'm thinking that the hosts file can be updated through telnet(maybe ?) but I know that the users info is kept in a few different places (including passwords, profiles and stuff)
Can somebody tell me
1. If there is something already written for that (or maybe UNIX already has those capabilites
2. And if not...what does it involve to write something like that. What are the different ways I can do it (and of course if it's possible)
3. Can you get me started maybe with a plan or an overall picture of how I need to go about it?
My language is C++. Unfortunately I don't know any UNIX languages(awk, sed or any shell stuff) but if I need to, I'm definitly willing to study them.
Would this be a long term project? To me it seems like it wouldn't be all that difficult but who knows? I've never done it before.
Comments
:
: I'm thinking that the hosts file can be updated through telnet(maybe ?) but I know that the users info is kept in a few different places (including passwords, profiles and stuff)
:
: Can somebody tell me
:
: 1. If there is something already written for that (or maybe UNIX already has those capabilites
: 2. And if not...what does it involve to write something like that. What are the different ways I can do it (and of course if it's possible)
: 3. Can you get me started maybe with a plan or an overall picture of how I need to go about it?
:
: My language is C++. Unfortunately I don't know any UNIX languages(awk, sed or any shell stuff) but if I need to, I'm definitly willing to study them.
:
: Would this be a long term project? To me it seems like it wouldn't be all that difficult but who knows? I've never done it before.
:
: :
: : I'm thinking that the hosts file can be updated through telnet(maybe ?) but I know that the users info is kept in a few different places (including passwords, profiles and stuff)
: :
: : Can somebody tell me
: :
: : 1. If there is something already written for that (or maybe UNIX already has those capabilites
: : 2. And if not...what does it involve to write something like that. What are the different ways I can do it (and of course if it's possible)
: : 3. Can you get me started maybe with a plan or an overall picture of how I need to go about it?
: :
: : My language is C++. Unfortunately I don't know any UNIX languages(awk, sed or any shell stuff) but if I need to, I'm definitly willing to study them.
: :
: : Would this be a long term project? To me it seems like it wouldn't be all that difficult but who knows? I've never done it before.
: :
:
:
:
C shell is not specifically designed to handle this type of thing, but it can be done. I would think you would want to use bash or korn if you are really looking to write a script for this. You would use the rcp command to do this. You are referring to an actually pretty simple script.
Another thing you 100% "HAVE" to know, is where all the files are that are affected when transferring user information.
The user information is in the /etc/passwd file. The passwords are in the /etc/shadow file, and the group information is in the /etc/group file.
An example would be:
--------------------------------------------------------
#!/sbin/ksh
### MAIN ###
for i in 1 2 3 4 5 6
do
{
for a in hosts group passwd shadow
do {
rcp /etc/$a server$i:/etc/hosts
}
done
}
done
## END OF FILE ##
--------------------------------------------------------
If you are familiar with C, then this should be pretty easy for you to understand. The first for statement is saying, do this while making i = 1,2,3,4,5, or 6. The $i in the rcp command is to change the number. So in this case server$i is all of the servers you are distributing to. (This is pretending the server names are in the format of: server1 , server2 , server3, etc.)
This is very similar to sorting in a sense (in C). The second for with the a, is changing the $a in the rcp command to be group,hosts, passwd, and then finally shadow. (shadow holds passwords, passwd holds user information, group holds group information, and hosts holds host information/ip addresses)
Try it out and see if this is what you were looking to accomplish. *NOTE THAT DEPENDING ON THE VERSION OF LINUX (whether it is RedHat or just plain Linux) DEPENDS ON THE RESULTS. SOME VERSIONS DISABLE REMOTE ACCESS.
Alternate Method:
Using the Remote Shell:
You could also write a script to handle this with a remote shell. For example you could have the same type of script as above but this time don't change the hosts file on the current server, let the script do it.
--------------------------------------------------
#/sbin/ksh
### MAIN ###
echo "
1. Create Entry in /etc/hosts
2. Create Entry in /etc/passwd
3. Create Entry in /etc/group
4. Create Entry in /etc/shadow
Please enter 1-4: c"
read answer #Takes user input and stores it in $answer
case $answer #checks answer and performs functions depending
in
1) file2edit = "/etc/hosts" ;; #sets variable $file2edit
2) file2edit = "/etc/passwd" ;;
3) file2edit = "/etc/group" ;;
4) file2edit = "/etc/shadow" ;;
*) echo "
THE NUMBER SELECTED IS NOT BETWEEN 1 and 4.
EXITTING...."
exit 0 ;;
esac
echo "
" #This creates two blank lines
echo "Please Enter line to Add: c"
read answer2
echo "
"
echo "You have entered:
$answer2
"
echo "Sending line to file ..."
for i in 1 2 3 4 5
do
{
rsh server$i echo "$answer2" >> $file2edit
echo "Line created in file $file2edit on server$i
"
}
done
## END OF FILE ##
Need anything let me know.
nishrevert@yahoo.com
:
: I'm thinking that the hosts file can be updated through telnet(maybe ?) but I know that the users info is kept in a few different places (including passwords, profiles and stuff)
:
: Can somebody tell me
:
: 1. If there is something already written for that (or maybe UNIX already has those capabilites
: 2. And if not...what does it involve to write something like that. What are the different ways I can do it (and of course if it's possible)
: 3. Can you get me started maybe with a plan or an overall picture of how I need to go about it?
:
: My language is C++. Unfortunately I don't know any UNIX languages(awk, sed or any shell stuff) but if I need to, I'm definitly willing to study them.
:
: Would this be a long term project? To me it seems like it wouldn't be all that difficult but who knows? I've never done it before.
:
:
That is generally NOT a good idea to do from a security standpoint. From the standpoint of network security, if someone should have access to multiple machines on the network, you would NOT want them to log in with their same old password on every machine. The issue is that it is much easier for a hacker to get accesss to the /etc/password file that way and then he would have everyone's password. If you do this, you should shift your password system over to shadow passwords. You should have a good sysadmin reference (like Coriolis) before attempting anything like this. You are liable to get yourself into trouble.
Paladin