Results 1 to 2 of 2

Thread: Parsing file, yaml file? Extracting specific sections

  1. #1
    Member prajithp13's Avatar
    Join Date
    Jun 2012
    Location
    India
    Posts
    26
    cPanel/WHM Access Level

    Root Administrator

    Default Parsing file, yaml file? Extracting specific sections

    Here is a data file, which I believe is in YAML. I am trying to retrieve just the "sub_domains" section, which doesnt seem to be as easy as I had originally thought. Any help on this would be greatly appreciated!! I have been trying to do this in perl, but its failed.

    This is actually from /var/cpanel/userdata/username/main


    Code:
    ---
    addon_domains:
    somedomain.com: mysubdomain.primarydomain.com
    somedomain2.com: mysubdomain2.primarydomain.com
    somedomain3.com: mysubdomain3.primarydomain.com
    cp_php_magic_include_path.conf: 0
    main_domain: primarydomain.com
    parked_domains: []

    sub_domains:
    - mysubdomain.primarydomain.com
    - mysubdomain2.primarydomain.com
    - mysubdomain3.primarydomain.com

  2. #2
    Member This forum account has been confirmed by cPanel staff to represent a vendor. KostonConsulting's Avatar
    Join Date
    Jun 2010
    Location
    Austin, TX
    Posts
    154
    cPanel/WHM Access Level

    Root Administrator

    Default Re: Parsing file, yaml file? Extracting specific sections

    cPanel has a set of functions built in to load configuration files. To load up a cPanel based YAML datastore, use Cpanel::CachedDataStore::loaddatastore like so:

    Code:
    my $username = 'someuser';
    my $configFile = '/var/cpanel/userdata/' . $username . '/main';
    my $configData = Cpanel::CachedDataStore::loaddatastore( $configFile, 0 );
    Then, you can access the different parts of $configData->{data} to get your variables:

    Code:
    #subdomains:
    my @subdomains = $configData->{data}->{sub_domains};
    #parked domains:
    my @parked_domains = $configData->{data}->{parked_domains};
    Though, if you're looking to gather this data, there's probably a better way to get what you want from within cPanel's code base. Look around in /usr/local/cpanel/Cpanel and you'll find tons of useful modules.
    Dave Koston
    Koston Consulting
    http://www.kostonconsulting.com

Similar Threads

  1. File Specific Bandwidth
    By succeed.net in forum cPanel & WHM Discussions
    Replies: 1
    Last Post: 02-01-2012, 04:23 AM
  2. How to get CPanel to recognize an edited filter.yaml file
    By sandali in forum E-mail Discussions
    Replies: 0
    Last Post: 06-28-2010, 10:59 AM
  3. File Manager problem extracting files
    By mkmagu in forum New User Questions
    Replies: 3
    Last Post: 03-15-2010, 07:55 AM
  4. bug in file manager when extracting files?
    By weetabix in forum cPanel & WHM Discussions
    Replies: 2
    Last Post: 08-05-2008, 10:57 AM
  5. Extracting a single file from the full backups
    By ZeusChicago in forum cPanel & WHM Discussions
    Replies: 6
    Last Post: 04-16-2007, 04:26 AM