#/bin/bash # Check in a local node whether the user as specified in /share/apps/configrepo/users_data/newuser.dat should be added, modified or left alone. Output would be shown as CASE 1, CASE 2, CASE 3, CASE 4 on screen. username=$(cat /share/apps/configrepo/users_data/newuser.dat | awk '{print $2}') uid=$(cat /share/apps/configrepo/users_data/newuser.dat | awk '{print $3}') passwd=$(cat /share/apps/configrepo/users_data/newuser.dat | awk '{print $4}') #echo 'username, uid= ' $username, $uid ## abstract all users with uid >= 1000 && < 4000 rm -rf /share/apps/configrepo/users_data/addstatus.dat echo yes > /share/apps/configrepo/users_data/addstatus.dat cat /etc/passwd | awk -F":" '{print $1, $3}' | awk '{if($2>=1000 && $2<4000) {print}}' | \ awk -v HOSTNAME=$HOSTNAME -v username="$username" -v uid="$uid" '{ if( $1 != username && $2 != uid ) # { # {print "CASE 4: username " username " with uid " uid " are not found in " HOSTNAME} # {print "yes" > "/share/apps/configrepo/users_data/addstatus.dat"} # } {dummy=dummy} else { #begin else {und=$1; uidd=$2} #{print username " " uid " clashes with existing record in #/etc/passwd: " $1 "," $2} {if( username != und && uid == $2 ) #begin if { {print "CASE 1 " "username " username " is different then $1= " und " but uid " uid " is the same with $2= " uidd " in " HOSTNAME} {print "No" > "/share/apps/configrepo/users_data/addstatus.dat"} {print "username " username " is different then $1= " und " but uid " uid " is the same with $2= " uidd " in " HOSTNAME >> "/share/apps/configrepo/users_data/addstatus_global.dat"} } };# end if {if( username == und && uid != $2 ) #begin if { {print "CASE 2 " "username " username " is the same with $1= " und " but uid " uid " is different then $2= " uidd " in " HOSTNAME} # {print "The uid " uid " in " HOSTNAME " is to be changed to " $2} {print "No" > "/share/apps/configrepo/users_data/addstatus.dat"} {print "username " username " is the same with $1= " und " but uid " uid " is different then $2= " uidd " in " HOSTNAME >> "/share/apps/configrepo/users_data/addstatus_global.dat"} } };# end if {if( username == und && uid == $2 ) #begin if { {print "CASE 3 " "username " username " is the same with $1= " und " and uid " uid " is the same with $2= " uidd " in " HOSTNAME} {print "No" > "/share/apps/configrepo/users_data/addstatus.dat"} {print "username " username " is the same with $1= " und " and uid " uid " is the same with $2= " uidd " in " HOSTNAME >> "/share/apps/configrepo/users_data/addstatus_global.dat"} } };#end if } #end else # end if }' #end awk addstatus=$(cat /share/apps/configrepo/users_data/addstatus.dat) #echo candiate in newuser.dat: $username $uid '$addstatus=' $addstatus in $HOSTNAME if [ $addstatus == 'yes' ] then #echo CASE 4 corresponds to '$addstatus=yes'. To add $username with uid=$uid in $HOSTNAME echo CASE 4 username $username with uid $uid are not found in $HOSTNAME fi