1748018 Members
3250 Online
108757 Solutions
New Discussion юеВ

query on perl - awk

 
SOLVED
Go to solution
Varghese Mathew
Trusted Contributor

query on perl - awk

Folks,

Being a novice in perl forces me to raise hands ...

Any idea how do I correct the script:
The script looks like:

#!/opt/perl/bin/perl
`cksum "/home/vm/erlog" | (awk '{print $1}') > "/home/vm/erlog.cksum"`;

I found the awk does not function properly in this perl script.

thanks in advance.
Cheers !!!
Mathew.
Cheers !!!
12 REPLIES 12
Michael Tully
Honored Contributor

Re: query on perl - awk

Hi Mathew,

I'm no perl guru either, but the script runs fine for me. I used the cksum on the /var/adm/syslog.log file. Only thing I can think of is the version of perl your using. These are latest:

http://www.software.hp.com/cgi-bin/swdepot_parser.cgi/cgi/displayProductInfo.pl?productNumber=PERL

or
http://hpux.connect.org.uk/hppd/hpux/Languages/perl-5.8.0/

HTH
Michael
Anyone for a Mutiny ?
Varghese Mathew
Trusted Contributor

Re: query on perl - awk

Hi Michael,

Thanks for that ...
I have upgraded the perl version to 5.8.x from 5.6.1, now. but still no hope ...

I would like to know how can we specify a specific shell like the "k shell" to be used for these shell command in side the perl script.

Looks to me like it could be the posix shell issue.

Cheers !!!
Mathew.
Cheers !!!
Ajit Natarajan
Valued Contributor
Solution

Re: query on perl - awk

I think your problem is that Perl is interpreting the $1 instead of passing it to awk.

Try the following: Replace $1 in your script with \$1

That should work.

Incidentally, when I invoked Perl with -w (enable warnings), I was able to easily determine the problem since Perl printed a helpful error message. I would recommend that you always execute Perl with -w. You can do this in your script with:

#!/opt/perl/bin/perl -w

Also, it is unclear to me why you are paranthesizing the awk command (awk ...). Doing so would invoke a subshell which in this case seems unnecessary.

Thanks.

Ajit
HP Gigabit Ethernet
Steven E. Protter
Exalted Contributor

Re: query on perl - awk

which /opt/perl/bin/perl

What answer to you get?

I'm not sure going to Perl 5.8 is going to impact this. Just make sure you are running the perl you think you are runing. The script should work.

I suppose check awk too.

P
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Varghese Mathew
Trusted Contributor

Re: query on perl - awk

Hi Ajit,

Yeah your suggestion could solve the issue ..

#!/opt/perl/bin/perl
`cksum "/home/vm/erlog" | (awk '{print \$1}') > "/home/vm/erlog.cksum"`;
d the issue..

Could this be something related with the POSIX shell or otherwise how did my earlier syntax did work for Michael? !!

Guys, many many thanks for that ..

Cheers !!!
Mathew.
Cheers !!!
Michael Tully
Honored Contributor

Re: query on perl - awk

Just for the record, I'm was running '/usr/bin/ksh' as 'root'
Anyone for a Mutiny ?
H.Merijn Brand (procura
Honored Contributor

Re: query on perl - awk

The question might be why the .... this is a perl script. It does not use perl at all

#!/usr/bin/sh
cksum /home/vm/erlog | awk '{print $1}' > /home/vm/erlog.cksum

does the same as a *shell* script with less overhead. Not that I object to perl, as the regulars will know, but there's a good tool for everything, and - in this case - it ain't perl.

Enjoy, have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
Ralph Grothe
Honored Contributor

Re: query on perl - awk

I'd like to agree to procura.

Wrapping external commands like cksum *and* even awk in a Perl script isn't only silly but a waste of resources.

But if you want to do your checksumming in soley Perl you could do it like this:


use Digest::MD5;

open FH, '/your/file/to/checksum'
or die "cannot open";

$md5 = Digest::MD5->new;
$md5->addfile(*FH);
close FH;
$md5sum = $md5->hexdigest;

Madness, thy name is system administration
harry d brown jr
Honored Contributor

Re: query on perl - awk


How about this:

#!/opt/perl/bin/perl
$logfile="/home/vm/erlog.cksum";
open(file, ">>$logfile") || die "open $logfile for cksum append \n";
printf file "%d\n",`cksum /home/vm/erlog`;



live free or die
harry
Live Free or Die