Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl Rover v3 pass environment variable to in the Rulesets

Tags:

perl

expect

I am using perl Rover module version 3 to login to the Linux/Unix server and run the script. In the ruleset if I add the full path name it copies the script to the remote server, not able to substitute the environment variable.

eg. This works:

 copy:{
       put_file "/home/u1/find.sh" "/tmp/"
        }; 

This didn't work:

copy:{
   put_file "$HOME/find.sh" "/tmp/"
    };

used $ENV{'HOME'}, this also didn't work.

How can I pass the environment variable?

Rover module document. http://rover.sourceforge.net/QuickStart/Rover-QuickStart-3.html#ss3.2

http://rover.sourceforge.net/

like image 489
sfgroups Avatar asked Aug 08 '12 23:08

sfgroups


People also ask

How do I pass an environment variable in Perl?

$path = $ENV{'PATH'}; As you may remember, %ENV is a special hash in Perl that contains the value of all your environment variables. Because %ENV is a hash, you can set environment variables just as you'd set the value of any Perl hash variable.

How do you pass an environment variable?

Environment variables can be used to pass configuration to an application when it is run. This is done by adding the definition of the environment variable to the deployment configuration for the application. To add a new environment variable use the oc set env command.

What does $ENV mean in Perl?

DESCRIPTION. Perl maintains environment variables in a special hash named %ENV . For when this access method is inconvenient, the Perl module Env allows environment variables to be treated as scalar or array variables.

What are go environment variables?

Environment variables are key-value pair on a system-wide level, and running processes can access that. These are often used to make the same program behave differently in different deployment environments like PROD, DEV, or TEST. Storing configuration in the environment is one of the principles of a twelve-factor app.


1 Answers

After reviewing the source code for rover, which I never used, I determined it was not possible from the existing code.

I created a new extension for you, that has that functionality, it supports the ~ and ${HOME} syntax, (which are bash extensions and not part of the OS directly, that is why perl does not support them).

code is here: https://github.com/h4ck3rm1k3/perl-rover/commit/2c78aefb97e819956bb665b04056763f8df1b242

I have had a hard time testing it because I never used rover before, and rover does not seem to support scp.(I read it is supported,but could not test it yet.) Anyway, let me know if you like it. I will put more work into it if reasonably requested.

Update

Here is my example ruleset :

example ruleset

[rulesets]
test:
{
       put_file_from_home put_file "~/find2.sh" "/tmp/"
       put_file_from_home put_file "${HOME}/find3.sh" "/tmp/"

},  ;

example output

Here is the example output, I cannot get rover to work. See the test case below.

Test output

perl -I lib  t/example2.t
Local was ~/find2.sh and home was /home/mdupont at lib/Rover/CoreExtension.pm line 19.
Local now /home/mdupont/find2.sh at lib/Rover/CoreExtension.pm line 22.
Local was ${HOME}/find3.sh and home was /home/mdupont at lib/Rover/CoreExtension.pm line 19.
Local now /home/mdupont/find3.sh at lib//Rover/CoreExtension.pm line 22.

new config option for the new sshport option

[hosts]
someexample:{
    os linux
    username myusername
    description 'myhost'
    sshport 12345
    ftp_method_used sftp
 };

update2

Dont use quotes around the name, use a comma between the args,

To [email protected]:h4ck3rm1k3/perl-rover.git 2207417..7637741 CoreExtension -> CoreExtension

[rulesets]

test: {     put_file_from_home ~/find2.sh,/tmp/ }, ;


[hosts]

localhost:{
    os linux
    username mdupont
    description 'localhost'
    ftp_methods sftp 
    ftp_method_used sftp  };

mike

like image 74
h4ck3rm1k3 Avatar answered Oct 31 '22 05:10

h4ck3rm1k3