![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Calling expect scripts from other expect scripts | seva | Shell Programming and Scripting | 0 | 04-03-2008 10:45 AM |
| FTP Scripts | raghav1982 | Shell Programming and Scripting | 27 | 12-07-2007 02:38 AM |
| use of ssh in scripts | esham | Shell Programming and Scripting | 7 | 11-16-2005 07:27 AM |
| Help with GDL to SQL scripts | ch4r1e5 | Shell Programming and Scripting | 0 | 10-31-2005 01:51 PM |
| using su in scripts | uchachra | UNIX for Dummies Questions & Answers | 3 | 03-11-2002 09:24 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
Hello all. I'm writing a script and I've run into a wall.
Basically what I want it to do, is mirror a users settings across different servers. I'm a newly employe'd AIX/Linux administrator, and I'm just trying some different thing. I work on 120 different servers, so if we can automate something - we do. Anyway, the problem is, how do I pull group information on a user? Whenever I try var=`id $user -gn` It will not work. I'll bold parts of the scripts that won't work. The other parts work. ################################### # Server mirror script. # Mirrors a user's information on one server, and adds the exact information on another server. ################################### # Variables id=accessid clear echo "What user do want to mirror?" read user1 echo " " echo " " echo "What server are we mirroring this user from? (Originating server)" echo "(E.G awojnare on p595_202, mirror all attributes over to focus, comet and falcon.)" read server1 echo " " echo " " echo "What server/s are we mirroring TO. Remember: Space's are delimited!" echo "(For the E.G above, this would be focus comet falcon .)" read list echo " " echo " " echo "Please hold while I slave over this for you." sleep 2 echo ".." echo " " sleep 2 echo "...." echo " " #Grab information for abcdefg in `echo $server1` do ssh -q $id@$abcdefg zaquid="sudo cat /etc/passwd | grep $user1 | cut -f3 -d ":""; primgroup="`id -Gn $user1`" #debugging - test the variables. echo $abcdefg echo $zaquid echo $primgroup echo $grouplist echo $server1 done sleep 2 echo " " echo "Okay, I got your information from $server1 and I'm going to add your information to server/s $list" sleep 2 echo ".." echo " " Information out to the servers for servera in $list do ssh -q $id@$servera "usermod -d /home/${user1} -g $primgroup -Gn $grouplist -u $uid -p apple1 $user1" done sleep 2 echo " " echo "Okay. ${user1}'s info, on $server1, has been mirrored over to ${list}." echo "${user1}'s password has been set to apple1." exit 0 My SECOND problem is: how do I run a loop within a SSH session? I'm writing this other script, that will sync up UID's across the 120 servers. It does not seem to want to work. I tried writing declaring a function, and then running the function within the SSH session (which is already in a for loop.) How would I write a nested for loop that would do this? How does one run a loop that SSH's out to all the servers in a predefined list, and then run a loop within that? Here is the code: function tmplist { for tmp in $tmpvar do chown $UID $tmp done } # Change the ownership for server3 in $list do ssh -q $id@$server3 "`tmplist`" done All the other variables are declared through read. Can someone help me? The function isn't working. I need to SSH out to all the servers. Everything else in the script works, but when I try and change the ownership of the old person's UID, it will not work with that function. Here is the full code: ############################################################# #This script will sync UID across AIX/Linux servers. ############################################################## #----------------------- Variables -----------------------# #id=`whoami` id=accessid tmpvar="/tmp/{$USER}uid.tmp" #----------------------- Functions -----------------------# function check1 { sudo grep -x $UID /etc/passwd | cut -d: -f3 } function check2 { sudo id -u $USER } function tmplist { for tmp in $tmpvar do chown $UID $tmp done } #----------------------------------------------------------# clear echo "\n \n \n" echo "This script will sync UID's across multiple servers." echo "It will also find all files owned by the user and set the ownership to the new UID." echo USER= while [ -z "$USER" ] ; do echo "What user has an incorrect UID on the servers? \c" read USER if [ -z "$USER" ] ; then echo "You must enter a valid User id...!" USER= fi done echo UID= while [ -z "$UID" ] ; do echo "What is the correct UID for $USER ? \c" read UID if [ -z "$UID" ] ; then echo "You must enter a UID...!" UID= fi done echo LIST= while [ -z "$list" ]; do echo echo "** Which servers do you want to sync UID's up on?" echo "** List the servers, space delimited (e.g., charger cobra cuda) \n \t \c" read list if [ -z "$list" ]; then echo "You have to enter at least one server!" list= fi done sleep 2 echo " " echo " " echo "Searching to see if the UID is being used on any user on $list." for server0 in $list do ssh -q $id@$server0 "variable1=`check1`" if [ "variable1 -ne $UID" ]; then echo "No UID found" else echo "UID already in use!!"; exit fi done sleep 2 echo " " echo " " echo "Searching to see if the UID is already being used by $USER" for server00 in $list do ssh -q $id@$server00 "variable2=`check2`" if [ "$UID -ne $variable2" ]; then echo "UID's are not the same. You may proceed" else "$USER already has an ID of $UID"; exit fi done echo " " echo " " sleep 2 echo " " echo "Searching for files owned by $USER, on the following servers: $list." echo "Hold.." echo "Any file found will be dumped into the temp file: /tmp/uid.tmp" echo " " for server in $list do ssh -q $id@$server "sudo find / -user $USER | grep -v proc | grep -v dev > /tmp/{$USER}uid.tmp" done sleep 2 # Change the UID for server2 in $list do ssh -q $id@$server2 "sudo usermod -u $UID $USER" echo "If this fails, the UID you're trying to change to is probably in use already" done sleep 2 # Change the ownership for server3 in $list do ssh -q $id@$server3 "`tmplist`" done sleep 2 # Delete the temp files. #for server4 in $list #do # ssh -q $id@$server4 "sudo rm /tmp/{$USER}uid.tmp" #done d echo "All finished!" exit 0 |
| Forum Sponsor | ||
|
|