[Canberra-pm] here document perl script

Kim Holburn kim at holburn.net
Thu Jun 8 20:55:22 PDT 2006


Awesome, Thanks.

On 2006 Jun 09, at 1:26 PM, James Ring wrote:

> Hi Kim
>
>> Thanks, that works.  Now how do I put the results in an  
>> environment var?
>>
>
> I now know more about Bash than I ever wanted to... but this should  
> work:
>
> #!/bin/sh
>
> x=$(
> /usr/bin/perl - $@ <<'EOP'
> use Socket;
>
> my $ip = $ARGV[0];
> my $addr = inet_aton($ip);
> my $name = gethostbyaddr($addr,AF_INET);
> my $ip2 = sprintf "%-20s", "[$ip]";
> if ($name eq "") { $name = "not found"; }
> my $begin .= $ip2 . $name;
> print "$begin\n";
> EOP
> )
>
> echo $x
>
> The quotes around the here document name cause Bash to not perform
> variable substitutions within the document, so pass $@ to Perl.  
> Putting
> the whole thing in x=$( ) seems to do the trick! :)
>
> Regards,
> James
> -- 
> James Ring
>
>

-- 
Kim Holburn
Security Manager, National ICT Australia Ltd.
Ph: +61 2 61258620 M: +61 417820641  F: +61 2 6230 6121
mailto:kim.holburn at nicta.com.au  aim://kimholburn
skype://kholburn - PGP Public Key on request
Cacert Root Cert: http://www.cacert.org/cacert.crt
Aust. Spam Act: To stop receiving mail from me: reply and let me know.
Use ISO 8601 dates [YYYY-MM-DD] http://www.saqqara.demon.co.uk/ 
datefmt.htm

Democracy imposed from without is the severest form of tyranny.
                           -- Lloyd Biggle, Jr. Analog, Apr 1961





More information about the Canberra-pm mailing list