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