remove debugging
[spider.git] / cmd / save.pl
1
2 # save the output of ANY command to a file
3 #
4 # Copyright (c) 2002 Dirk Koopman G1TLH
5 #
6 # $Id$
7 #
8
9 my ($self, $line) = @_;
10 return (1, $self->msg('e5')) if $self->priv < 9 || $self->remotecmd;
11
12 my ($date_req, $time_req);
13 my $app_req = '>';
14 if ($line =~ /-d/) {                    # add a date to the end of the filename
15         $line =~ s/\s*-d\s*//;
16         $date_req = 1;
17 }
18 if ($line =~ /-t/) {                    # add a time to the end of the filename
19         $line =~ s/\s*-t\s*//;
20         $time_req = 1;
21 }
22 if ($line =~ /-a/) {                    # append to the file
23         $line =~ s/\s*-a\s*//;
24         $app_req = '>>';
25 }
26
27 #$DB::single = 1;
28
29 my ($fn, $rest) = split /\s+/, $line, 2;
30 $fn = "$main::root/packclus/$fn" unless $fn =~ m|^/|;
31 $fn =~ s/\.\.//g;
32 $fn =~ s|/+|/|g;
33 $fn .= '_' . cldate if $date_req;
34 $fn .= '_' . ztime if $time_req;
35 $fn =~ s/\s+//g;
36
37 my @cmd;
38 if ($rest =~ /^\s*\"/) {
39         @cmd = split /\s*\"[\s,]?\"?/, $rest;
40 } else {
41         push @cmd, $rest;
42 }
43 open OF, "$app_req$fn" or return (1, $self->msg('e30', $fn));
44 for (@cmd) {
45         print OF map {"$_\n"} $self->run_cmd($_);
46 }
47 close OF;
48 return (1, $self->msg('ok'));
49
50