Skip to main content

Posts

Showing posts with the label read readln

Parse password file and populate variables

#!/bin/bash #ypcat passwd > /tmp/passwd cp /etc/passwd /tmp/passwd while IFS=: read -r user pass uid gid gecos home shell do   echo "ipa-moduser -a -s \"$shell\" -c \"$gecos\" -d \"$home\" $user" done < /tmp/passwd exit 0 Another approach... #!/bin/sh # 1 is the nis domain, 2 is the nis master server ypcat -d $1 -h $2 group > /dev/shm/nis-map.group 2>&1 IFS=$'\n' for line in $(cat /dev/shm/nis-map.group); do   IFS=' '   groupname=$(echo $line|cut -f1 -d:)   # Not collecting encrypted password because we need cleartext password to create kerberos key   gid=$(echo $line|cut -f3 -d:)   members=$(echo $line|cut -f4 -d:)   # Now create this entry   ipa group-add $groupname --desc=NIS_GROUP_$groupname --gid=$gid   if [ -n "$members" ]; then     ipa group-add-member $groupname --users=$members   fi   ipa group-show $groupname done