no output from perl script

tim.conway at philips.com tim.conway at philips.com
Tue Apr 23 13:48:02 EST 2002


The filehandle trick is a fine way to do it, but I want to point out that 
some of the output comes on STDERR, so you might want to add a "2>&1" just 
before the pipe in your open()..... that is, of course if you want that 
info... stuff like:
opendir(test/license.management/logsnap): Permission denied
opendir(test/test/license.management/logsnap): Permission denied
link_stat sjtnetsvr:/tmp : No such file or directory
rsync error: partial transfer (code 23) at 
../../../../src/rsync-2.5.5rc1/main.c(578)

Tim Conway
tim.conway at philips.com
303.682.4917
Philips Semiconductor - Longmont TC
1880 Industrial Circle, Suite D
Longmont, CO 80501
Available via SameTime Connect within Philips, n9hmg on AIM
perl -e 'print pack(nnnnnnnnnnnn, 
19061,29556,8289,28271,29800,25970,8304,25970,27680,26721,25451,25970), 
".\n" '
"There are some who call me.... Tim?"




Harry Putnam <reader at newsguy.com>
Sent by: rsync-admin at lists.samba.org
04/22/2002 10:00 PM

 
        To:     <rsync at lists.samba.org>
        cc:     (bcc: Tim Conway/LMT/SC/PHILIPS)
        Subject:        Re: no output from perl script
        Classification: 



Robert Silge <rsilge at mac.com> writes:

> You are quite right. I fixed that up, here is the current incarnation of 
the
> script, but still no output revealed.
>
> Also if anyone who actually knows something about perl could tell me how 
to
> have it reprint the first print command if a valid choice is not entered
> that would be pretty slick. I could add an "exit" choice so that it 
would
> keep giving you a chance to get it right until you type exit.
>
> But that's not really essential. Seeing what's going on is (or at least
> close to essential).

Rob, here is a little different approach.  It makes use of variable to
a greater extent, and prints a menu where choices are made until one
takes you out of the program.

It also makes use of subroutines to contain the various actions.
You'll note I used the notation `&subroutine' to call the functions.
There are other ways, but I like that one.

You'll notice too that I only filled in the first subroutine to give
the idea, the others are just simple print and exit.  You'll have to
file them in.

Now about seeing the output of the rsync command.  There are several
ways.  Using the backtic like you did is one.  But I'd use hte
notation qx(command args targets).  Just for clarity. It works same as
backtics. But you need to put it in a print statement to see the
output like this:

print qx($cmd $flags $remote $local);
exit;

Another way and probably the cleanest is to use the filehandle
approach where you use perls filehandle notation to run a process

# Notice the pipe at the end.  That allows you to get at the output in a
# while loop.

open(PROC,"$cmd $args $remote $local|");
while(<PROC>) {
# print each line.   But you could do other stuff here too
   print $_;
}
# Close the process
close(PROC);
exit;

Either of those techniqes will do it.  I'm leaving it up to you to see
how to fit them into opt setup.  But basically just insert the filled
out code in the appropriate sub function.


I did'nt debug this so it is definitely only an example of one way
approach the problem.

========================================
#!/usr/bin/perl -w

## BEGIN VARIABLE[s] ============================================

$remote = "SOME.MACH:/home/user/rsync-testing";
$local  = "/home/user";
$cmd    = "/path/to/rsync";
$flags  = '-auvz --progress --delete -e ssh';

## BEGIN SCRIPT BODY ===========================================

## Start up a while loop that will display a menu until we exit
## or our choice completes the program
do {
  do {
    &display;
    chomp($opt = <STDIN>);
  }while ($opt < 0 && $opt >3);

  if ($opt == 1) {
    &opt1
  }

  if ($opt == 2) {
    &opt2
  }

  if ($opt == 3) {
    &opt3
  }

## A rule that keeps the loop running until we opt out.
} while ($opt != 3);

## BEGIN FUNCTION[S] ===========================================
sub display {
  print <<EOM;
Which computer do you wish to delete files from?
(type corresponding number)
1] Remote

2] Local

3] quit
EOM
} 

sub opt1 {
  print "we are doing option one\n";
  print <<EOM; 
This command will DELETE EVERYTHING in Local~/Research
UNLESS it is also found in Remote~/Research.
Do you really wish to do this?
(Anything but a \`yes' here will abort the action)
[N/yes]: 
EOM
  chomp($answer = <STDIN>);
    if ($answer eq "yes") {
      print "\nOK, here we go.\n";
      print " This is an example only so it only prints a possible 
command\n";
      print "Here is where to use the qx notation or PROC notation\n";
      print "$cmd $flags
             $remote $local\n";
      exit;
    }
}

sub opt2 {
  print "we are doing option two\n";
  exit;
}

sub opt3 {
  print "We are doing option three... we gone ..bye bye\n";
  exit;
}


-- 
To unsubscribe or change options: 
http://lists.samba.org/mailman/listinfo/rsync
Before posting, read: http://www.tuxedo.org/~esr/faqs/smart-questions.html







More information about the rsync mailing list