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

A

Asif Iqbal

#!/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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top