I think the problem is not with perl, but with your shell.
For the most shells () and [] are metacharacters (in bash [] is for
pattern matching and () is to fork a process, me thinks).
You either have to put the entire paramline into ''. Than you have
to alter your perl-programm, because you just get one paramter.
But that woul be easy. Just replace
@zin = @ARGV
with
@zin = split/\s+/, $ARGV[0];
Another solution would be to escape all the metacharacters (write
\(, \], and so on on the commandline).
A third way would be to pass the line to the perl-skript on STDIN.
Than you'd have to say:
$line = <STDIN>;
chomp $line;
@zin = split/\s+/, $line;
hope this helps,
cr
On Thu, 3 May 2001 14:41:39 +0200, jose said:
> Hi,
>
> I'm having a problem with a script. This is a bit of a long story, but I hope
>someone can help me. I've been busy with it now for two weeks, and I still don't know
>how to get it working perfectly. I'm used to C, and perl is rather new to me. Thanks
>in advance.
>
> I would like to thank Collin Rogowski and Greg Meckes for helping me the other day,
>getting some stupid newbie errors out of my script.
>
> What I wanna do is the following:
>
> I'm running WOTS, this is a log checker based on perl. If it encounters a certain
>string, it can output it in certain ways. What I do is I let it execute my script
>called ./namescript and append the string it got >from the logfile. These are some
>examples:
>
> ../namescript Mar 16 12:12:04 ns4 named-xfer[16809]: [212.104.202.50] not
>authoritative for ero-art.com, SOA query got rcode 0, aa 0,
> ancount 0, aucount 12
>
> ../namescript Mar 14 12:14:00 ns4 named-xfer[16876]: connect(212.104.19710) for
>zone reeshof.nl failed: Connection refused
>
> ../namescript Mar 13 17:30:05 ns4 named-xfer[13847]: [212.104.197.10] not
>authoritative for hvb-hypotheken.nl, SOA query got rcode 2, aa 0,
> ancount 0, aucount 0
>
> What the script does is that it has to check the ip adres in the string, and make
>an email for our customers to check their nameserver. It compares the ip adres, to
>the IF statements, and fills some variables so It can make the email, and send it.
>
> What I'm doing is split the string bij spaces, and put it in an array (I'm doing
>this, so I can use pieces of the string in the mail I'm sending to our customers)
> This works fine if I don't use the following signs in the string: ( ) [ ]
> If I do it like here under I don't have any problems:
>
> ../namescript Mar 16 12:12:04 ns4 named-xfer16809: 212.104.202.50 not authoritative
>for ero-art.com, SOA query got rcode 0, aa 0,
> ancount 0, aucount 12
>
> ../namescript Mar 14 12:14:00 ns4 named-xfer16876: connect 212.104.197.10 for zone
>reeshof.nl failed: Connection refused
>
> ../namescript Mar 13 17:30:05 ns4 named-xfer13847: 212.104.197.10 not authoritative
>for hvb-hypotheken.nl, SOA query got rcode 2, aa 0,
> ancount 0, aucount 0
>
> But if I do it like : (This is the output from the log, appended to my script)
>
> ../namescript Mar 16 12:12:04 ns4 named-xfer[16809]: [212.104.202.50] not
>authoritative for ero-art.com, SOA query got rcode 0, aa 0,
> ancount 0, aucount 12
>
> ../namescript Mar 14 12:14:00 ns4 named-xfer[16876]: connect(212.104.19710) for
>zone reeshof.nl failed: Connection refused
>
> ../namescript Mar 13 17:30:05 ns4 named-xfer[13847]: [212.104.197.10] not
>authoritative for hvb-hypotheken.nl, SOA query got rcode 2, aa 0,
> ancount 0, aucount 0
>
> It always gives the error : NO MATCH
> The scripts exits, and doesn't mail anything. I already tried to do:
>
> ../namescript Mar 16 12:12:04 ns4 named-xfer[16809]: [212.104.202.50] not
>authoritative for ero-art.com, SOA query got rcode 0, aa 0,
> ancount 0, aucount 12 | sed "s#\[##g" | sed "s#\]##g" | sed "s#(##g" | sed "s#)##g"
> (This is supposed to remove the ( ) [ ] )
>
> But then it doesn't recognise it, and just mails me the string without putting it
>in the array.
>
> So my question is, can I remove the ( ) [ ] while reading the ARGV and replace it
>with a space or something, this is the last problem I've got. I don't know why it
>gives me the error NO MATCH when it detects a ( ) [ ].
>
> Thanks in advance
>
> Jose Vazquez
> [EMAIL PROTECTED]
>
> ################################
> #!/usr/bin/perl -w
>
> my @zin = @ARGV; #put string in an array
> my $t;
> my $name;
> my $email;
> my $bericht;
> my $tick;
> my $z;
>
> print "@zin\n"; #just for testing
>
> $tick = "0";
> $z = 20;
>
> #for ($t=0;$t<$z;$t++) {
> # print "$zin[$t] [$t]\n\r";
> #}
>
> for ($t=0;$t<$z;$t++) {
>
> if ($zin[$t] eq "212.104.202.50") {
> $name = "NS1.NETCASE.NL";
> $email = '[EMAIL PROTECTED]';
> $bericht ="Hoi wij krijgen de melding $zin[6] $zin[7] $zin[8] $zin[9] van $name,
>kunnen jullie hier iets aan doen?";
> $tick = "1";
> $t = $z;
> }
>
> elsif ($zin[$t] eq "212.104.194.5") {
> $name = "NS.VSM-HOSTING.NL";
> $email = '[EMAIL PROTECTED]';
> $bericht ="Hoi wij krijgen de melding $zin[6] $zin[7] $zin[8] $zin[9] van $name,
>kunnen jullie hier iets aan doen?";
> $tick = 1;
> $t = $z;
> }
>
> elsif ($zin[$t] eq "195.114.231.200") {
> $name = "NS2.SUPPORT.NL";
> $email = '[EMAIL PROTECTED]';
> $bericht ="Hoi wij krijgen de melding $zin[6] $zin[7] $zin[8] $zin[9] van $name,
>kunnen jullie hier iets aan doen?";
> $tick = 1;
> $t = $z;
> }
>
> elsif ($zin[$t] eq "212.104.201.196") {
> $name = "NS1.SCHROER.NL";
> $email = '[EMAIL PROTECTED]';
> $bericht ="Hoi wij krijgen de melding $zin[6] $zin[7] $zin[8] $zin[9] van $name,
>kunnen jullie hier iets aan doen?";
> $tick = 1;
> $t = $z;
> }
>
> elsif ($zin[$t] eq "212.104.197.10") {
> $name = "NS1.PROMISUM.NL";
> $email = '[EMAIL PROTECTED]';
> $bericht ="Hoi wij krijgen de melding $zin[6] $zin[7] $zin[8] $zin[9] van $name,
>kunnen jullie hier iets aan doen?";
> $tick = 1;
> $t = $z;
> }
>
> elsif ($zin[$t] eq "212.104.195.194") {
> $name = "NS1.NLWEBSERVICE.COM";
> $email = '[EMAIL PROTECTED]';
> $bericht ="Hoi wij krijgen de melding $zin[6] $zin[7] $zin[8] $zin[9] van $name,
>kunnen jullie hier iets aan doen?";
> $tick = 1;
> $t = $z;
> }
>
> elsif ($zin[$t] eq "212.104.210.2") {
> $name = "NS.CLICKHERE.NL";
> $email = '[EMAIL PROTECTED]';
> $bericht ="Hoi wij krijgen de melding $zin[6] $zin[7] $zin[8] $zin[9] van $name,
>kunnen jullie hier iets aan doen?";
> $tick = 1;
> $t = $z;
> }
> }
>
> if ($tick eq "1") {
> # this one is for sending the email if it recognises the IP
> open(M,"|/usr/sbin/sendmail $email") || die $!;
> print M "Subject: Er is een fout opgetreden bij ophalen domein van uw
>nameserver!\n";
> print M "\n"; # header en body scheiden dmv een lege regel
> print M "$bericht";
> close M;
>
> }
>
> elsif ($tick eq "0") {
> # this one is for the rest!
> $email = '[EMAIL PROTECTED]';
> open(M,"|/usr/sbin/sendmail $email") || die $!;
> print M "Subject: Fout op nameserver!\n";
> print M "\n"; # header en body scheiden dmv een lege regel
> print M "@zin";
> close M;
> exit;
> }
>
>
> ########################################
>
>