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

Discussion in 'Ruby' started by Asif Iqbal, Aug 6, 2009.

  1. Asif Iqbal

    Asif Iqbal Guest

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





    --
    Asif Iqbal
    PGP Key: 0xE62693C5 KeyServer: pgp.mit.edu
    A: Because it messes up the order in which people normally read text.
    Q: Why is top-posting such a bad thing?
     
    Asif Iqbal, Aug 6, 2009
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. BeGreen
    Replies:
    14
    Views:
    2,428
    BeGreen
    Aug 14, 2006
  2. GenxLogic
    Replies:
    3
    Views:
    1,327
    andrewmcdonagh
    Dec 6, 2006
  3. Replies:
    19
    Views:
    1,154
    Daniel Vallstrom
    Mar 15, 2005
  4. Replies:
    1
    Views:
    512
  5. perl_help_needed

    how to parse data between two date ranges

    perl_help_needed, Aug 8, 2005, in forum: Perl Misc
    Replies:
    11
    Views:
    187
    Gunnar Hjalmarsson
    Aug 10, 2005
Loading...

Share This Page