You can take a look at the IPC::Cmd module that should remove some pain
when dealing with system commands through Perl.

 https://metacpan.org/pod/IPC::Cmd


On Thu, May 15, 2014 at 3:10 PM, Chris Knipe <sav...@savage.za.org> wrote:

> Hi All,
>
> I'm having a bit of a strange issue executing a system command through
> perl.
> The system command reads a bunch of parameters through STDIN, and responds
> via STDOUT.  The problem is that special commands (notably the "#" and "!"
> character.  Perl itself, escapes the characters correctly (as indicated
> through the print $RADCommand code), but the command once executed through
> the shell, but from there it goes pear shaped once the system executes the
> command..
>
> A quick example:
> use Data::Dumper;
> use strict;
> use warnings;
> my $AuthName = "user\@domain.com";
> my $AuthPass = "!\@#bsay0nd";
> my $ClientIP = "10.0.0.3";
> my $RADCommand = "/bin/echo -e ";
> $RADCommand .= "Called-Station-Id = x.x.x.42, ";
> $RADCommand .= "Calling-Station-Id = " . $ClientIP . ", ";
> $RADCommand .= "Login-Service = Telnet, ";
> $RADCommand .= "Login-TCP-Port = 119, ";
> $RADCommand .= "NAS-IP-Address = 10.255.255.245, ";
> $RADCommand .= "NAS-Port-Type = Virtual, ";
> $RADCommand .= "Service-Type = Authenticate-Only, ";
> $RADCommand .= "User-Name = " . $AuthName . ", ";
> $RADCommand .= "User-Password = " . $AuthPass . " ";
> $RADCommand .= "| /usr/bin/radclient -c 1 -r 1 -t 5 10.255.251.4 auth
> quaap5hooZae4ahNguehusieg0Oiph1u";
> my @RADResult = qx($RADCommand);
> print $RADCommand . "\n";
> print Dumper(@RADResult);
>
> The output of the above code is correct:
> /bin/echo -e Called-Station-Id = 85.12.8.42, Calling-Station-Id =
> 198.19.255.3, Login-Service = Telnet, Login-TCP-Port = 119, NAS-IP-Address
> =
> 10.255.255.245, NAS-Port-Type = Virtual, Service-Type = Authenticate-Only,
> User-Name = gar...@beyondonline.co.za, User-Password = !@#Bey0nd |
> /usr/bin/radclient -c 1 -r 1 -t 5 10.255.251.4 auth
> quaap5hooZae4ahNguehusieg0Oiph1u
> $VAR1 = 'Received response ID 198, code 3, length = 55
> ';
> $VAR2 = '       Reply-Message = "NOK:::::::::Authentication failed"
> ';
>
> However, once executing the command, the RADIUS server receives the
> incorrect string for the password:
> Thu May 15 09:57:46 2014
>         Packet-Type = Access-Request
>         Called-Station-Id = "x.x.x.42"
>         Calling-Station-Id = "10.0.0.3"
>         Login-Service = Telnet
>         Login-TCP-Port = 119
>         NAS-IP-Address = 10.255.255.245
>         NAS-Port-Type = Virtual
>         Service-Type = Authenticate-Only
>         User-Name = " u...@domain.com"
>         User-Password = "!@"
>         Realm = "DEFAULT"
>
> The problem is a shell problem rather than a perl problem, I do know that
> much.  Nevermind what I do or where I put quotes / escape strings, I cannot
> get bash to execute the echo statement.
>
> Can anyone shed some light on this subject perhaps?  I know it's more than
> likely a little bit off topic, but I would appreciate the assistance.
>
> --
> Chris.
>
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>

Reply via email to