DX Unified Infrastructure Management

 View Only
  • 1.  setting specroot using Spectrum::CLI

    Posted Sep 10, 2015 09:16 AM

    Hi All,

     

    I'm using the perl module Spectrum::CLI for some scripts. It is (still) very useful and makes using the vnmsh commands in a perlscript very straightforward.

    For instance show devices can be achieved like this:

     

    my $cli = new Spectrum::CLI;

    my @DeviceListAoH = $cli->show_devices

     

    What you get back is an array of hashes. Each line is stored as a hash in the array. The hash holds each column, so all output is available.

    All happy so far and starting this from bash shell works fine. The only requirement is that the SPECROOT must be set in bash.

     

    Now I want to start my script using cron which does not have this SPECROOT set and ever since the script does not work

     

    The readme for Spectrum:CLI states the following:

     

     

    <new> - create a new Spectrum::CLI object

     

       $obj = Spectrum::CLI->new([VNM_Name,]
                                 [SPECROOT,]
                                 [ {
                                    [verbose => 1,]
                                    [Verbose => 1,]
                                    [CLISESSID => $sessid,]
                                    [CLIMNAMEWIDTH => $width,]
                                    [VNMSHRCPATH => $path,]
                                    [localhostname => $localname,]
                                    [timeout => $seconds,]
                                 } ]);

     

      my $cli = new Spectrum::CLI;

     

    Checked the several examples which came with the module but none of them show an example where the SPECROOT needs to be set

     

    In one of the examples I see this:

     

    my $cli = new Spectrum::CLI { CLIMNAMEWIDTH => 16, verbose => 1 }, $ARGV[0];

     

    I can't reproduce this with setting the specroot... (In the meantime I've been told how to set the environment for cron using the source command but I want to set it using the actual script which calls the method)

     

    Anybody any clue as to how this should work?

     

    many thanks

    Hans



  • 2.  Re: setting specroot using Spectrum::CLI

    Posted Sep 10, 2015 10:55 AM

    Hans,

     

    It may not be SPECROOT that needs to be set but CLISESSID. From the Command Line Interface User Guide:

     

     

    CLISESSID

     

    Represents the ID for use in scripts. Set the CLISESSID variable to <$$>, which represents the process ID of the running shell script. This variable is necessary when using cron to run CLI scripts concurrently. For example, using the bash shell:

     

    CLISESSID=<$$>; export CLISESSID

     

    Also, setting the CLISESSID environment variable to a unique value for each CLI session is required if you run CLI on Windows using the bash shell instead of DOS. You can give a unique timestamp to each bash shell, for example:

     

    export CLISESSID='date +%s'

     

    Regards,

     

    Joe

     



  • 3.  Re: setting specroot using Spectrum::CLI

    Posted Sep 11, 2015 02:45 AM

    Hi Joe,

     

    Thanks for your reply, I know about the CLISESSID but the Spectrum::CLI module takes care of that. I have 2 workarounds working

    1) I set the SPECROOT for the CRON using the source command before starting the actual perl script

    2) I modified the Spectrum/CLI.pm so the SPECROOT in statically coded in there

     

    both workariounds won't win any beauty contest so I'm trying to figure out how to do this a bit more clean....

     

    Hans



  • 4.  Re: setting specroot using Spectrum::CLI

    Posted Sep 11, 2015 04:24 AM

    In the <$SPECROOT> directory, there is file called .spectrum80.env.

     

    I usually use your option 1 to source this file (you can set the CLIMNAMEWIDTH as well).

     

    e.g.:

     

    0 */2 * * * source /opt/spectrum/.spectrum80.env; /opt/spectrum/custom/scriptName.pl
    
    

     

    Alternatively you can set up a .bash_profile for the spectrum user (or script user) and then point to that (with it sourcing other files if needed).

    This can be useful if you want to set aliases, etc.

     

    Alternatively the REST API is very flexible and more powerful with most things in Spectrum. I still use vnmsh for some things which can't be done with REST.