Operating System - HP-UX
1833874 Members
2305 Online
110063 Solutions
New Discussion

Re: convert in hpux commands, script written in linux commands

 
Deepu Chakravarty
Regular Advisor

convert in hpux commands, script written in linux commands

I have one perl script written in linux commands. Can someone convert it so that it can run in hpux 11.11? Script is as follows:

#!/usr/bin/perl -w
## Usage:
## perl osw_vmstat_parse.pl
## where is the name of an individual OSW vmstat archive file
## The utility will produce an output file in the form of:
## osw_vm_yymmdd_hhmm.txt
## where yymmdd_hhmm is month, day, year, hours taken from the time portion of
## input archive file.
##
##
use Time::Local;
## build hash table of month name to string
%Month = (
"Jan" => 0,
"Feb" => 1,
"Mar" => 2,
"Apr" => 3,
"May" => 4,
"Jun" => 5,
"Jul" => 6,
"Aug" => 7,
"Sep" => 8,
"Oct" => 9,
"Nov" => 10,
"Dec" => 11

%MetaColumns = ();
%ReverseColumns = ();
# initialize stuff here
$version = "1.0";
$carlage = 0; ## handy counter
$definedMeta = "FALSE";
$lineCount = 0; ## to store overall "good" lines
if (! $ARGV[0])
{
print "\n";
print "osw_vmstat_parse.pl Version ", $version, " Usage: \n";
print "perl osw_vmstat_parse.pl \n";
print "where is a vmstat archived file produced by OSWatcher.\n";
exit 1;
}
$fileName = $ARGV[0];
# will be in this form: hostname.oracle.com_vmstat_07.11.09.1300.dat
# chop up name, grab date
($host, $dummy, $date_part) = split("_", $fileName);
$year = substr($date_part, 0, 2);
$month = substr($date_part, 3, 2);
$day = substr($date_part, 6, 2);
$hours = substr($date_part, 9, 4);
## osw_vm_yymmdd_hhmm.txt
## while we have the values, build output filename
$fileOut = "osw_vm_" . $year . $month . $day . $hours . ".txt";
open(INFILE, $fileName) or die "File ", $fileName, " cannot be opened.\n";
## create output filename from input filename
##
while ($line = )
{
# first, chop into array of tokens
@thisline = split(" ", $line);
# grab version of OSW
if ($thisline[1] eq "OSW" )
{
($platform, $dummy, $version, $host) = @thisline; $platform="";
}
# parse out date/time stamp
if ($thisline[0] eq "zzz" )
{
#zzz ***Mon Oct 29 10:01:24 EDT 2007
($junk, $wkday, $month, $mday, $time, $zone, $year) = split(" ", $line);
$junk = $zone; ## just to eliminate spurious warnings
$wkday = substr($wkday, 3);
($hours, $min, $sec) = split(":", $time);
$timeseconds = timelocal($sec, $min, $hours, $mday, $Month{$month}, $year);
}
if ($thisline[0] eq "procs") { }; # do nothing, header thing
if ($thisline[0] eq "r" && $definedMeta eq "FALSE") # col hdrs
{
$colCount = 0;
## save off a "list" of columns, in original order
@columnNames = @thisline;
foreach $column (@thisline)
{
# first the obverse
$MetaColumns{$column} = $colCount;
# then the reverse
$ReverseColumns{$colCount} = $column;
$colCount++;
}
$definedMeta = "TRUE";
}
## now eat first two lines of vmstat output
if ($thisline[0] =~ /^\d+$/ && $thisline[1] =~ /^\d+$/ )
{
$carlage++;
if ($carlage == 3) # ...and the number of the counting shall be three.
{
$bucketNumber = 0;
foreach $bucket (@thisline)
{
$bucketName = $ReverseColumns{$bucketNumber};
push @$bucketName, $bucket;
$bucketNumber++;
}
push @timestamp, $timeseconds;
$carlage = 0; ## reset to a value suitable for carl
$lineCount++; ## bump "good" lines, so we know later
}
}
}
## knock out a text file of stuff
## osw_vm_yymmdd_hhmm.txt
open (TXTOUT, "> $fileOut") or die "Cannot open ", $fileOut, "for writing\n";
print TXTOUT "timestamp ";
foreach $col (@columnNames)
{
print TXTOUT $col, " ";
}
print TXTOUT "\n";
$lines = 0;
while ($lines < $lineCount)
{
print TXTOUT $timestamp[$lines], " ";
foreach $col (@columnNames)
{
print TXTOUT $$col[$lines], " ";
}
print TXTOUT "\n"; ## never forget the linefeed!
$lines++; ## and bump da pointer
}
close TXTOUT;
5 REPLIES 5
Patrick Wallek
Honored Contributor

Re: convert in hpux commands, script written in linux commands

I'm not sure what you mean by "written in linux commands." At a first glance I don't see any OS level commands in the perl script.

Perl is very portable and the same script should run on Linux and HP-UX just fine.

Have you tried running this script on HP-UX? If so, did you get any errors? If you did get errors it would help immensely if you posted those errors.
Yogeeraj_1
Honored Contributor

Re: convert in hpux commands, script written in linux commands

hi,


Since this is perl, it will work similar to the linux environment.

obvious changes will concern line 1:
#!/usr/bin/perl -w

where you will have to refer to the appropriate location of perl on your hp-ux 11.11 host. (do "which perl" to get the exact path)

However, calls to hp-ux commands may require individual analysis. E.g. vmstat output can be different on Linux compared to the HP-UX environment.

I would suggest that you break the script in smaller modules and try them individually, one by one.

good luck!

kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Deepu Chakravarty
Regular Advisor

Re: convert in hpux commands, script written in linux commands

Hi,

It is giving following error:

$ perl osw_vmstat.pl
Unrecognized character \xCD at osw_vmstat.pl line 18.

'which perl' gives following path:

$ which perl
/usr/bin/perl
Hein van den Heuvel
Honored Contributor

Re: convert in hpux commands, script written in linux commands

When I tossed (cut & paste) the text above into an HPUX file the semicolons (;) turned into dots (.).
Looks like that source is in UNICODE.
Paste it into a notepad, save as ANSI TEXT.
Open the TEXT file, cut & paste from there.
Ah... the seimicolons stay.
And the program works... or at least prints the help text when no args ar provided.

fwiw... is is not the pretties perl / parsin I've seen. Hard to read with constructs like:
"if ($thisline[0] eq "procs") { }; # do nothing, header thing"

I guess it serves as documentation, but why?

Cheers,
Hein.






VK2COT
Honored Contributor

Re: convert in hpux commands, script written in linux commands

Hello,

Hein is right, your Perl script was probably written on a Windows machine and used
the encoding 'utf-8'.

Certain editors (in particular on win32) may
add a UTF-8 Byte Order Marker (BOM:

http://www.unicode.org/faq/utf_bom.html#BOM)

at the beginning of the file. It creates a
situation where BOM appears past the
beginning of the file...

To test it further:

# hexdump -C osw_vmstat_parse.pl (Linux)

or

# od -t a osw_vmstat_parse.pl (HP-UX)

Your script is not wrong (albeit not
the best coding technique). Encoding is.

Cheers,

VK2COT
VK2COT - Dusan Baljevic