How to read parse data from two file to generate one one file

#!/usr/bin/ruby

ARGF.each do |line|
sunetid, tmp, uid, gid, name, homedir, shell = line.split(/:/)
puts " user { “” + sunetid + “”:"
puts " ensure => “present”,"
puts " uid => “” + uid + “”,"
puts " gid => “” + gid + “”,"
puts " comment => “” + name + “”,"
puts " home => “” + homedir + “”,"
puts " shell => “” + shell.chomp + “”,"
puts " }"
puts “”
end

This file take the a password file and generate some output per user.

How do I feed it passwd and shadow files and generate
a file per user with another key => value like password => ‘hashkey
from shadow’
along with the key => value then it already generates?

So instead of the current output like

user { "dbbkp":
    ensure  => "present",
    uid     => "12346",
    gid     => "70006",
    comment => "DB Backup User - See rsync in cron",
    home    => "/home/dbbkp",
    shell   => "/usr/local/bin/bash",
}

I want it to generate an output like this

   user { "dbbkp":
    ensure  => "present",
    uid     => "12346",
    gid     => "70006",
    shadow => "iaUGiJld2XMKM"  # it will get that value from shadow 

file
comment => “DB Backup User - See rsync in cron”,
home => “/home/dbbkp”,
shell => “/usr/local/bin/bash”,
}

here passwd file entry looks like this

dbbkp:x:12346:70006:DB Backup User - See rsync in
cron:/home/dbbkp:/usr/local/bin/bash

and shadow file entry looks like this

dbbkp:iaUGiJld2XMKM:::::::

Thanks for the help

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs