Kevin, On Tuesday 14 November 2006 16:18, Randall R Schulz wrote:
Kevin,
On Tuesday 14 November 2006 15:33, Kevin Donnelly wrote:
I have a list of usernames and passwords in a csv file, and what I'm trying to do is loop through each user, run the password through htpasswd, and write both to a file for Apache directory restriction.
The usernames and passwords are in fields 9 and 10 of the file respectively, and I was trying to do the loop via: for user in $(awk 'BEGIN { FS = ";" } ; {print $9}' user_pw.csv) do password="awk 'BEGIN { FS = ";" } ; {print $10}' user_pw.csv)
The outer-most (first) double quote on this line is unclosed. BASH continues on to the next line looking for its mate. If I put a quote at the end of that line, target /etc/passwd, change the FS to ':' and change the field numbers to accommodate that file's format, the script appears to work.
echo "User $user has password $password" done
Gack. That was all wrong. Try this: for user in $(awk 'BEGIN { FS = ":" } ; {print $1}' /etc/passwd) do password="$(egrep "^$user" /etc/passwd |awk 'BEGIN { FS = ":" } ; {print $4}')" echo "User $user has password $password" done Of course, that's not very efficient, since it reads all of the password file (in your case, user_pw.csv) for each user, but for one-off purposes, it's adequate. Randall Schulz --------------------------------------------------------------------- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org