Since that last awk line gives you a list of user names, all you need to do is cycle through the list and grab the shadow line for each one.
I recommend setting up a function for this, then you can run it through sort to put it all in order and remove any duplicates.
Also, unless you have some specific need (i.e. compatibility with shells that don't have it), $()
is recommended over `` backticks.
Finally, I think the IFS setting is superfluous here, unless there's a chance that there are spaces or tabs in the lines. And the field separator setting in awk takes care of that anyway.
Code:
#!/bin/bash
function shadowlist() {
for i in $( awk -F ":" '$3 >= 1 && $3 < 500 { print $1 }' /etc/passwd ) ; do
grep "$i" /etc/shadow
done
}
shadowlist | sort -u #sort the list output and remove duplicates.
exit 0
By the way, I have no idea why it's printing duplicate lines, but grep seems to think there are multiples for some reason. If you don't want to use "sort -u" to filter them, you can instead use the option "-m 1" in grep to tell it to only print the first match.