[CentOS] OT: bash script for passwd and shadow manipulation

Stephen Harris lists at spuddy.org
Thu Nov 27 19:37:36 UTC 2008


On Thu, Nov 27, 2008 at 01:56:11PM -0500, Erick Perez wrote:
> So far, cut returns the name up to the space, so in this case it will
> return Kimaura and not Kimaura Thomas.

No, it doesn't.

> # for linia in `cat /etc/passwd`

This is your mistake.  Think about it
  for linia in `cat /etc/passwd`
  do
    echo Line just read: $linia
  done

That shows what is going wrong; the "in" is splitting at the white space.

What you should be doing
  cat /etc/passwd | while read linia
instead.

Even better would be
  while read linia
  do
   ....
  done < /etc/passwd

Or, to rewrite the whole program in a one line awk script:

awk -F: '{printf("zmprov ma %s@'$domain' displayName %s\n",$1,$5)}' /etc/passwd > $file

-- 

rgds
Stephen


More information about the CentOS mailing list