tags:

views:

60

answers:

2

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.

+1  A: 
awk -F":" ' $3 > 499 {print $1} ' /etc/passwd | sudo grep -f - /etc/shadow > shadow.out
Dennis Williamson
Cool. I haven't ever used the -f flag of grep. I guess it basically means "match any of these lines"?
bradlis7
@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
+1  A: 

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
Yeah, I noticed that too.
bradlis7