I need help
I have two input files and I'd like to generate a report based on the two.
filea:
hostname,account1,password
,account2,password
hostname,account1,password
hostname,account1,password
,account1,password
,account2,password
repeating hostnames are blank
fileb:
hosta
hostb
hostc
I need to generate a record of "hostname account password" for all hosts in fileb that occur in filea for a specific account. I.e. I want a list of root passwords for all hosts in fileb. I know the logic I want to use but don't have the scripting skills to implement it. I think the easiest way would be to use awk to fill in the blanks with the hostname of filea and then simply use a shell script to grep for each host in fileb of the new filea.
The other way is to run down filea for each hostname in fileb until either the account is matched or the hostname is different and print the result. If the account does not exist for the given hostname do nothing.
I'm trying to save manually doing this by scripting it thinking it would be faster but maybe I was wrong
Here is the framework I came up with so far for the harder way because it would be more elegant
#!/bin/sh
#
hosts=`cat hosts.txt`
hostname="x"
last="x"
for name in ${hosts}
do
#the awk logic would come here
done