1

I'm looking for a way to copy all non-system users from one PC to another. I can get the group and passwd files copied over using this

awk -F":" ' $3 > 499 ' etc/passwd >> /etc/passwd
awk -F":" ' $3 > 499 ' etc/group >> /etc/group

But, how would I go about getting the shadow file copied over since it does not store the UID? Assume that there are over 1000 users, so doing a grep with the usernames, such as egrep '(bob|bill|sarah|sal):' etc/shadow >> /etc/shadow generating the usernames from the awk code above, would be a bit inefficient, but a possible option.

bradlis7
  • 3,375
  • 3
  • 26
  • 34

2 Answers2

2

awk -F":" ' $3 > 499 {print "^"$1":"} ' /etc/passwd | sudo grep -f - /etc/shadow > shadow.out

Previous answer could produce multiple lines per user if username is part of other usernames

Peter
  • 21
  • 2
1
awk -F":" ' $3 > 499 {print $1} ' /etc/passwd | sudo grep -f - /etc/shadow > shadow.out
Dennis Williamson
  • 346,391
  • 90
  • 374
  • 439
  • Cool. I haven't ever used the -f flag of grep. I guess it basically means "match any of these lines"? – bradlis7 May 07 '10 at 22:01
  • @bradlis7: `grep -f patternfile textfile` means look in "patternfile" for a list of patterns to search "textfile" with. Using `-` as the filename means to use standard input. – Dennis Williamson May 07 '10 at 23:42