Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

changes to etc/passwd file 1

Status
Not open for further replies.

grapes12

Technical User
Mar 2, 2010
124
ZA
herewith is my script
Code:
FILE1=$ORACLE_SQL
FILE2=/etc/passwd
cp $FILE2 /etc/passwd.$$.orig

while IFS=":" read user comment
do
 user=$(echo $user | tr -d ' ')
 [ -z "$(awk -F: "/^$user:/"' && $5 == "" {print $2}' $FILE2)" ] || usermod -c "$
comment" $user
done <$FILE1

BUT now if a change is made on the database, and the script is run, script does not pick up changes...and does not make any amendments in /etc/passwd file
any ideas?????
 
Add some debugging:

Code:
FILE1=$ORACLE_SQL
FILE2=/etc/passwd
cp $FILE2 /etc/passwd.$$.orig

while IFS=":" read user comment
do
 user=$(echo $user | tr -d ' ')
 echo "processing $user"
 echo "passwd entry is $(awk -F: "/^$user:/" $FILE2)"
 if [ -z "$(awk -F: "/^$user:/"' && $5 == "" {print $2}' $FILE2)" ] 
 then
   echo "updating comment to: $comment"
   usermod -c "$comment" $user
 else
   echo "no modification made, comment is already defined: $(awk -F: "/^$user:/"' {print $5}' $FILE2)"
 fi
done <$FILE1

Annihilannic.
 
Thanks for the star. Did that help you find the problem? If so, what was it?

Annihilannic.
 
Yes it helped.
If a change is made on the table in the database e.g A women getting married and her surname changes, the script must be able to run adhoc so that the changes can come into effect on the /etc/passwd file as well.
Now to have my senior test it..
 
Oh no..he is not satisfied.
He made a change on the etc/passwd file.the script is not changing the comment field.
here is script:
Code:
FILE1=$ORACLE_SQL
FILE2=/etc/passwd
cp $FILE2 /etc/passwd.$$.orig

while IFS=":" read user comment
do
 user=$(echo $user | tr -d ' ')
 echo "Processing $user"
 echo "Passwd entry is $(awk -F: "/^$user:/" $FILE2)"
 if [ -z "$(awk -F: "/^$user:/"' && $5 == "" {print $2}' $FILE2)" ]
 then
   echo "Updating comment to: $comment"
   usermod -c "$comment" $user
 else
   echo "No modification made, comment is already defined: $(awk -F: "/^$user:/"
' {print $5}' $FILE2)"
 fi
done <$FILE1

Database data is correct, but change not made in /etc/passwd
Code:
sha:x:3375:500:HRP/HRP Shaun2Alberts:/u1/home/sha:/bin/ksh

Is there something wrong with my script..i thought is was correct!


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top