9

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/

Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
sfgroups
  • 18,151
  • 28
  • 132
  • 204

2 Answers2

4

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 git@github.com: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

h4ck3rm1k3
  • 2,060
  • 22
  • 33
  • i tried it today, didn't work in debug I got this message. 'Before match string: `put $HOME/test.txt test.txt $HOME/test.txt test.txt\r\nFile \"$HOME/test.txt\" not found.\r\r\n', it not replacing $HOME with varible value, tried ${HOME}, ~/test.txt also. didn't work – sfgroups Aug 19 '12 at 00:36
  • perl path is incorrect in the first line. ./rover -bash: ./rover: perl: bad interpreter: No such file or directory – sfgroups Aug 19 '12 at 00:37
  • perl shbang, it was wrong in the original version, I fixed it . https://github.com/h4ck3rm1k3/perl-rover/commit/1540a96336d0a635c1338dbca120a80af2acd703 – h4ck3rm1k3 Aug 19 '12 at 04:08
  • I have provideded how I test it. I have to travel today, will be back in 18 hours, I will see if I can setup a local test of rover. – h4ck3rm1k3 Aug 19 '12 at 04:34
  • thanks for update, not sure am getting the right code. it says method is missing. thread failed to start: Can't locate object method "put_file_from_home" via package "Rover". I grep all the files, not finding this function. find .. -type f -name "*pm" -print|xargs grep "put_file_home" – sfgroups Aug 19 '12 at 17:59
  • checked out the code from branch, example code works, now I getting this error message. thread failed to start: Can't locate object method "put_file_from_home" via package "Rover" at /usr/lib/perl5/site_perl/5.8.8/Rover.pm line 1172. Use of uninitialized value in concatenation (.) or string at /usr/lib/perl5/site_perl/5.8.8/Rover.pm line 1092. Use of uninitialized value in numeric eq (==) at /usr/lib/perl5/site_perl/5.8.8/Rover.pm line 1093. copied all the file in correct location /usr/lib/perl5/site_perl/5.8.8/Rover/CoreExtension.pm – sfgroups Aug 19 '12 at 18:38
  • put_file_from_home you need to make sure that package is loaded. Make sure you get my branch (git checkout CoreExtension). https://github.com/h4ck3rm1k3/perl-rover/commit/2c78aefb97e819956bb665b04056763f8df1b242 you need something like this – h4ck3rm1k3 Aug 20 '12 at 12:47
  • I did checked out the laste code and copied to correct location.here is file size. -r--r--r-- 1 root root 50027 Aug 20 20:18 /usr/lib/perl5/site_perl/5.8.8/Rover.pm -rwxr-xr-x 1 root root 670 Aug 20 08:34 /usr/lib/perl5/site_perl/5.8.8/Rover/CoreExtension.pm you example code works also. perl example2.t Local was ~/find2.sh and home was /home/testu at /usr/lib/perl5/site_perl/5.8.8/Rover/CoreExtension.pm line 19. Local now /home/testu/find2.sh at /usr/lib/perl5/site_perl/5.8.8/Rover/CoreExtension.pm line 22. – sfgroups Aug 21 '12 at 00:26
  • OK, i will have to setup an example, it looks like the code is working, maybe there are problems with the rover integration. I will check that it works here better. – h4ck3rm1k3 Aug 21 '12 at 04:14
  • Ok, now I tested and fixed the bugs. Silly errors. I had to extend the code to handle a different ssh port. Config like this: `[hosts] someexample:{ os linux username myusername description 'myhost' sshport 12345 ftp_method_used sftp }; ` – h4ck3rm1k3 Aug 21 '12 at 05:43
  • I want to say again, sorry for untested integration into rover, it was very hard to test and I needed to hack the code to work with a different ssh port to test it on the server I use. I never used rover, but the code is now working and committed. https://github.com/h4ck3rm1k3/perl-rover/commit/a62363844db14f195161d1109c847f03e460ca9d – h4ck3rm1k3 Aug 21 '12 at 05:53
  • thaks for your help. I downloaded this code again. now it displays the message, it not executing. did you add exit some where? at /usr/lib/perl5/site_perl/5.8.8/Rover/Core/FTP.pm line 53. Rover::Core::FTP::determine_ftp_method('Rover::Host=HASH(0x69aeb00)', 'setup') called at /usr/lib/perl5/site_perl/5.8.8/Rover.pm line 761 Rover::ftp_login('Rover=HASH(0x5fb63d0)', 'xxxx') called at /usr/lib/perl5/site_perl/5.8.8/Rover.pm line 1109 Rover::run_rulesets('Rover=HASH(0x5fb63d0)', 'test', 'HASH(0x698cf00)') called at /usr/bin/rover line 1116 – sfgroups Aug 22 '12 at 15:03
  • oh, let me check. I tested it and got it working. oops that was a branch I did not test! confess "setting port ". Dumper($host_obj); if the ssh port was not set. commented it out. To git@github.com:h4ck3rm1k3/perl-rover.git a623638..3c8932f CoreExtension -> CoreExtension. Please test again! sorry, testing this is a *******. – h4ck3rm1k3 Aug 22 '12 at 15:43
  • Is it working now? please mail me directly jamesmikedupont@gmail.com if you have any issues. – h4ck3rm1k3 Aug 23 '12 at 19:31
  • didn't work. gibing this messae at /usr/lib/perl5/site_perl/5.8.8/Rover.pm line 1104. Rover::run_rulesets('Rover=HASH(0x6de93d0)', 'test', 'HASH(0x77e1b10)') called at ./rover line 1113 here is rules; test: { put_file "~/test.txt" "/tmp/" }, ; – sfgroups Aug 25 '12 at 00:40
  • host entry in the config file. [hosts] xxx{ os Linux ftp_methods sftp ftp_method_used sftp }; – sfgroups Aug 25 '12 at 00:42
  • I did not make it, i have so many things to do, give me more time. – h4ck3rm1k3 Aug 29 '12 at 16:24
  • you need to use put_file_from_home not put_file for the new function, I did not overwrite the function, but defined a new one. – h4ck3rm1k3 Aug 31 '12 at 00:44
  • Ok, now it works, omg what a nightmare! please test are report bugs, sorry for the delay. – h4ck3rm1k3 Aug 31 '12 at 05:39
0

Old question but new answer, since your using Rover v3 you can just extend the Rover::Core modules by overloading it.

Add this to your ~/.rover/contrib directory:

CoreVariables.pm:

package CoreVariables;

use strict;
use Exporter;
our @ISA = qw( Exporter );
our @EXPORT = qw( put_file );

sub put_file {
  my ($self, $host, $command) = @_;

  $command =~ s/(\$[\w{}]+)/$1/eeg;
  return Rover::Core::put_file($self, $host, $command);
}

And add the following to your ~/.rover/config [modules] section (must be after Rover::Core):

CoreVariables:{
};

And then you can store environment variables in your rover config when using put_file. Add other routines if you wish, this only extends put_file.

And since this is such an easy task I will add it to the requested feature list and include it in the next release (I am the Rover author).

The better place to ask Rover questions is on the sourceforge website of course: http://sourceforge.net/projects/rover/

Bryan Bueter
  • 95
  • 1
  • 5