summaryrefslogtreecommitdiff
path: root/scripts/system/vyatta_update_syslog.pl
blob: d02d8be0f572635cd7ecbeda8e7922b020f9e4ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/perl

use strict;
my $SYSLOG_CONF = '/etc/syslog.conf';

my $match1 = shift;
my $match2 = shift;
my $update_line = shift;

if (!defined($match1) || !defined($match2) || !defined($update_line)) {
  exit 1;
}

if (system("touch $SYSLOG_CONF")) {
  exit 2;
}

my $exp1 = "";
my $exp2 = "";
if ($match1 ne "") {
  $exp1 = $match1;
  if ($match2 ne "") {
    $exp2 = $match2;
  }
} elsif ($match2 ne "") {
  $exp1 = $match2;
}

if ($exp2 ne "") {
  if (system("sed -i '/$exp1/{/$exp2/d}' $SYSLOG_CONF")) {
    exit 2;
  }
} elsif ($exp1 ne "") {
  if (system("sed -i '/$exp1/d' $SYSLOG_CONF")) {
    exit 3;
  }
}

if ($update_line ne "") {
  open my $out, '>>', $SYSLOG_CONF or  exit 4;
  print {$out} "$update_line";
  close $out;
}

exit 0;