Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Awk integrating command with variable

Status
Not open for further replies.

rgruppo

IS-IT--Management
Dec 23, 2011
2
FR
Hello,

I am beginner with awk and I would like to resolve the following problem :
I have a csv file which content : key,username,password.
I would like to make a shell script in order to load them in my htpasswd file.

Example of the csv file :

Key,username,password
User,John,pass_john
User,Marcia,pass_marcia
NotUser,William,pass_Will

There is one condition, if in the first field there is the word "User" then I would like to update his password in htpasswd otherwise I don't want to update anything

The following code seems not to be working, It is like the command htpasswd is not working.

#!/usr/bin/ksh

awk -F "," '{if ($1=="User"){"/path/apache/bin/htpasswd -mb /path_file/wtpasswd "$2" "$3;}}' file.csv

The command to update a password should respect the following format :
/Path_htpasswd/htpasswd -mb /Path_fileUserPass/wtpasswd username password


If you can help me it would be great.
Thanks,
 
What about this ?
Code:
awk -F "," '{if ($1=="User")[!]system([/!]"/path/apache/bin/htpasswd -mb /path_file/wtpasswd "$2" "$3[!])[/!]}' file.csv

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks a lot!
It is working.
Best regards,
RG
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top