server.ini Site Sorting Script – Request for Comments

Clovertech Forums Read Only Archives Cloverleaf Tcl Library server.ini Site Sorting Script – Request for Comments

  • Creator
    Topic
  • #48766

    I have put together a small script that sorts the sites in the server.ini file. I’d appreciate any comments on how to improve the script before I add a nightly cron job.

    Code:

    #! /usr/bin/perl -lw

    ################################################################################
    #
    # Name: sortServerIni.pl
    # Developer: Max Drown
    # Date: 09/07/2006
    # Purpose: sort the list of sites in the server.ini file
    # Usage: sortServerIni.pl
    # Example: sortServerIni.pl /opt/quovadx/qdx5.2/integrator/server/server.ini
    #
    ################################################################################

    use File::Copy;

    $org = “$ARGV[0]”;
    $bak = “$ARGV[0].bak”;
    $tmp = “$ARGV[0].tmp”;

    copy($org, $bak);

    open(FILE, “>$tmp”);

    while (<>) {

       chop;

       if (/environs=/) {
           s/environs=//;
           @sites = split(/;/);
           @sites = sort(@sites);
           $sites = join “;”, @sites;
           print FILE “environs=$sites”;
       } else {
           print FILE;
       }
    }

    close(FILE);

    move($tmp, $org);

    -- Max Drown (Infor)

Viewing 2 reply threads
  • Author
    Replies
    • #59607
      Anonymous
      Participant

        Max,

        what are you trying to achive by sorting the sites?

        Are you planning to use it for cycle sites?

        Thx

        reggie

      • #59608

        A nice, sorted list in the Cloverleaf GUI.  ðŸ˜€

        http://www.planetdrown.com/images/cloverleaf_sorting_sites.jpg" />

        -- Max Drown (Infor)

      • #59609
        Russ Ross
        Participant

          Yes I too wanted a sorted listing and have even been thinking about some visual delimiters.  

          It is easier for me just to share my approach and let you decide than for me to evalute your approach.

          Nonetheless, I just looked and right now I have 94 test sites and 57 production sites, so you can see my similar need to order sites so I can locate the one of interest.  

          My approach was a bit different because I don’t always use the GUI to create or change a site name so I have sites that sometimes are not even in the server.ini file.  

          My approach does the follwoing

          – makes a bakup copy of server.ini file

          – dynamically creates current listing of all sites of interest

          – uses current site listing to replace “environs=” stuff in server.ini

          I wrote the following 3 scripts to accomplish this:

          set_server_ini_environs.ksh

          Code:

          #!/usr/bin/ksh

          # the purpose of this script is to set the environs variable in the server.ini file
          # so that it has all our Cloverleaf sites in sorted order

          # History:
          #
          # 2005.08.17 Russ Ross wrote initial version
          #

          cp -p $HCIROOT/server/server.ini
               $HCIROOT/server/server.ini_`date +”%Y.%m.%d_%H:%M:%S”`

          perl -pi -e “s,^environs=.*$,`mk_server_ini_environs.ksh`,”
               $HCIROOT/server/server.ini

          mk_server_ini_environs.ksh

          Code:

          #!/usr/bin/ksh

          # the purpose of this script is to create the statement to initialize the environs variable
          # which can be redirected to a temp file like x.x and then manually inserted
          # into the server.ini file so the Cloverleaf sites will appear in sorted order in the GUI

          # History:
          #
          # 2005.06.21 Russ Ross wrote initial version

          envorns_statement=”environs=”
          for site in `list_sites.ksh`; do
              envorns_statement=”$envorns_statement$HCIROOT/$site;”
          done
          echo “$envorns_statement” | perl -pi -e “s/;$//”

          list_sites.ksh

          Code:

          #!/usr/bin/ksh

          # Begin Module Header ==============================================================================
          #
          #——
          # Name:
          #——
          #
          # list_sites.ksh
          #
          #———
          # Purpose:
          #———
          #
          # List all the sites for the current $HCIROOT
          #
          #——–
          # Inputs:
          #——–
          #
          # none
          #
          #——-
          # Notes:
          #——-
          #
          # This script assumes the proper environment is set when it is called
          # and all sites are symbolic links at the $HCIROOT level
          #
          #———
          # History:
          #———
          #
          # 2001.02.22 Russ Ross
          #          – wrote initial version.
          #
          # 2001.07.25 Russ Ross
          #          – modified to look for $HCIROOT/*/siteInfo files to determine the list of sites,
          #            previously had looked for symbolic links in the $HCIROOT directory which only
          #            works if everyone follows MDACC conventions
          #
          # 2003.11.17 Russ Ross
          #          – modified to execlude siteProto from the list of sites
          #
          # End of Module Header =============================================================================

          #—————————————————————————————–
          # get a list of all the sites for the current $HCIROOT
          # (Note:  there is an assumption that all sites are a symbolic link at the $HCIROOT level)
          #—————————————————————————————–

          (cd $HCIROOT; ls ./*/siteInfo 2>/dev/null) | awk -F/ ‘{print $2}’ | grep -v siteProto | sort


          Code:

          Russ Ross
          RussRoss318@gmail.com

      Viewing 2 reply threads
      • The forum ‘Tcl Library’ is closed to new topics and replies.