#!/bin/bash cat iplist | while read ip username do printf "${ip}, ${username}, " eval $(ssh -q ${ip} "awk -v user_name=$username -F':' '$0 ~ user_name {printf("user_id=%s group_id=%s", $3, $4)}' /etc/passwd" < /dev/null) printf "${user_id}, ${group_id} " done
awk与shell之间变量的互传。