CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Creating Remote Directories with a wrapper

 



blues
New User

Jul 26, 2012, 11:22 AM

Post #1 of 6 (2120 views)
Creating Remote Directories with a wrapper Can't Post

I have a script that pushes out a perl script to multiple machines and collects system information. These are all Solaris 10 spare servers. Everything works great accept my directory creation on the remote machine.
If I login and run it manually it works fine, but does not work when I run it from my wrapper script.

My system_info.pl is copied to /tmp on the remote machine using scp and expect. It then runs with sudo locally.

Here are a few lines from the wrapper and system_info script.

my wrapper contains the following sudo command to execute the system_info.pl locally.


Code
 
$sudo_cmd = "cd /tmp ; sudo perl system_info.pl ; exit";


and here is part of the expect piece that runs the command


Code
 
[ qr/admin\@$server\s*\$\s/ => sub { $cmd->send("$sudo_cmd\n"); } ],



The system_info.pl script that is copied
contain's the following lines to create the directory. Again tis works if I login and run system_info.pl manually, but not remotely with the wrapper.


Code
 
if (-d "/usr/local/adm/log") {

open MYLOG, "+>", "/usr/local/adm/log/system_info.log" or die $!;
}
else {
mkdir ("/usr/local/adm", 0755);
mkdir ("/usr/local/adm/log", 0755);
open MYLOG, "+>>", "/usr/local/adm/log/system_info.log" or die $!;
}



Any help would be appreciated.

Thank you
-blues


rovf
Veteran

Jul 27, 2012, 4:14 AM

Post #2 of 6 (2100 views)
Re: [blues] Creating Remote Directories with a wrapper [In reply to] Can't Post


Quote
but does not work when I run it from my wrapper script.


What is does not work supposed to mean? Does it die silently? Does it blow up the system? ....?


blues
New User

Jul 27, 2012, 7:19 AM

Post #3 of 6 (2090 views)
Re: [rovf] Creating Remote Directories with a wrapper [In reply to] Can't Post

It does not create the directory on the remote hosts and the script exits. Then the wrapper script fails to copy the log back since it does not exist.

scp: /usr/local/adm/log/system_info.log: No such file or directory
Cannot open Log file No such file or directory

Then my terminal is messed up and I have to type
`stty sane` to get it back to normal.

Thanks
-blues


FishMonger
Veteran / Moderator

Jul 27, 2012, 7:32 AM

Post #4 of 6 (2089 views)
Re: [blues] Creating Remote Directories with a wrapper [In reply to] Can't Post

Besides the missing info on what you mean by "does not work", I see a logic issue.

If the directory exists, the log file gets opened on write mode clobbering everything that was in it, but if it doesn't exist, then it's opened in append mode after the directory is created.

The modes are reversed from what they should be.

Personally, I'd do it this way:

Code
use File::Path qw(make_path); 

my $path = '/usr/local/adm/log';

if ( not -d $path ) { make_path($path, {mode => 0755}) }

open my $log_fh, '>>', "$path/system_info.log"
or die "failed to open '$path/system_info.log' <$!>";



FishMonger
Veteran / Moderator

Jul 27, 2012, 7:35 AM

Post #5 of 6 (2087 views)
Re: [blues] Creating Remote Directories with a wrapper [In reply to] Can't Post

Is stderr on the remote side being directed back and are you capturing that info?

Do you have any logging in place that logs the errors/warnings generated on the remote side?

Is the wrapper script connecting with the same cradentials as when you login locally?


(This post was edited by FishMonger on Jul 27, 2012, 7:37 AM)


FishMonger
Veteran / Moderator

Jul 27, 2012, 7:43 AM

Post #6 of 6 (2084 views)
Re: [blues] Creating Remote Directories with a wrapper [In reply to] Can't Post

You might want to look at using File::Remote
http://search.cpan.org/~nwiger/File-Remote-1.17/Remote.pm

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives