add the save and echo commands
[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 my ($fn, $rest) = split /\s+/, $line, 2;
28 $fn .= '_' . cldate if $date_req;
29 $fn .= '_' . ztime if $time_req;
30 $fn =~ s/\s+//g;
31
32 my @cmd;
33 if ($rest =~ /^\s*\"/) {
34         @cmd = split /\s*\"[\s,]?\"?/, $rest;
35 } else {
36         push @cmd, $rest;
37 }
38 open OF, "$app_req$fn" or return (1, $self->msg('e30', $fn));
39 for (@cmd) {
40         print OF map {"$_\n"} $self->run_cmd($_);
41 }
42 close OF;
43 return (1, $self->msg('ok'));
44
45