Translating script to perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Translating script to perl
# 1  
Old 01-07-2014
Translating script to perl

awk/shell:

Code:
       

                UWARNING=90
                UCRITICAL=97

                PXNAME=$(echo $line | awk -F, '{print $1}')
                SVNAME=$(echo $line | awk -F, '{print $2}')

                FRUPERCENT=$(echo $line | awk -F, '{print ($5 / $7) * 100}')
                FRUSTATUS=$(echo $line | awk -F, '{print $18}')

                if [ "${FRUSTATUS}" = "OPEN" ] ; then

                        awk "BEGIN {

                                if($FRUPERCENT<$UWARNING)
                                        {
                                                print \"OK: svname($SVNAME)=${FRUPERCENT}% , STATUS_OPEN , pxname($PXNAME)\" ; exit 0 }

                                else if(($FRUPERCENT>=$UWARNING) && ($FRUPERCENT<$UCRITICAL))
                                        {
                                                print \"WARNING: svname($SVNAME)=${FRUPERCENT}% , STATUS_OPEN , pxname($PXNAME)\" ; exit 1 }
                                else if ($FRUPERCENT>=$UCRITICAL)
                                        {
                                                print \"CRITICAL: svname($SVNAME)=${FRUPERCENT}% , STATUS_OPEN , pxname($PXNAME)\" ; exit 2 }
                                else
                                        {
                                                print \"UNKNOWN: svname($SVNAME)=${FRUPERCENT}% , STATUS_OPEN , pxname($PXNAME)\" ; exit 3}
                                }"

                elif [ "${FRUSTATUS}" != "OPEN" ] ; then

                        awk "BEGIN {

                                if($FRUPERCENT<$UWARNING)
                                        {
                                                print \"CRITICAL: STATUS_NOTOPEN , svname($SVNAME)=${FRUPERCENT}% , pxname($PXNAME)\" ; exit 2 }
                                else if(($FRUPERCENT>=$UWARNING) && ($FRUPERCENT<$UCRITICAL))
                                        {
                                                print \"CRITICAL: STATUS_NOTOPEN , svname($SVNAME)=${FRUPERCENT}% , pxname($PXNAME)\" ; exit 2 }
                                else if ($FRUPERCENT>=$UCRITICAL)
                                        {
                                                print \"CRITICAL: STATUS_NOTOPEN , svname($SVNAME)=${FRUPERCENT}% , pxname($PXNAME)\" ; exit 2 }
                                else
                                        {
                                                print \"UNKNOWN: STATUS_NOTOPEN , svname($SVNAME)=${FRUPERCENT}% , pxname($PXNAME)\" ; exit 3}
                                }"
                fi

is there anyway this can be translated to perl? this is part of a very large script. if i can translate the above to perl, i can redo the other script based on how the above is translated to perl.

any help is much appreciated.

Last edited by SkySmart; 01-22-2014 at 07:07 PM..
# 2  
Old 01-07-2014
While not recommended, the perl monks admit this sh to PERL app exists: Clive Darke / App-sh2p-0.06 - search.cpan.org
This User Gave Thanks to DGPickett For This Post:
# 3  
Old 01-07-2014
This isn't just shell script you have submitted so any translator is probably not going to work. This also contains awk script. There have been a number of times in my career where there just isn't an easy way to handle large and many times poorly written scripts. You just have to attempt to understand them in a top down fashion and re-write them. In this case, I always make sure I am not trying to correct something that really isn't broken. What problem will you solve by converting this to perl?
This User Gave Thanks to blackrageous For This Post:
# 4  
Old 01-07-2014
Quote:
Originally Posted by SkySmart
any help is much appreciated.
hand translate yourself and learn some Perl. for example this
Code:
PXNAME=$(echo $line | awk -F, '{print $1}')

is just getting the first field of a comma delimited line. you can
use split() in Perl for this.
# 5  
Old 01-08-2014
Quote:
Originally Posted by SkySmart
awk/shell:
is there anyway this can be translated to perl? this is part of a very large script. if i can translate the above to perl, i can redo the other script based on how the above is translated to perl.

any help is much appreciated.
Skysmart,
Rather than asking someone to change entire script to perl Smilie , you could have understand the logic and ask doubts in that.

By seeing, it is not a very big script. It just have some "if" conditions.
So try to do it yourself and ask any doubts Smilie either in bash or in perl.

Happy coding Smilie
# 6  
Old 01-08-2014
Quote:
Originally Posted by blackrageous
This isn't just shell script you have submitted so any translator is probably not going to work. This also contains awk script. There have been a number of times in my career where there just isn't an easy way to handle large and many times poorly written scripts. You just have to attempt to understand them in a top down fashion and re-write them. In this case, I always make sure I am not trying to correct something that really isn't broken. What problem will you solve by converting this to perl?
it isn't by choice that i have to write this in perl. i've been doing this long enough to know the language used to write a script is utterly irrelevant as long as you know precisely what it is you want and you also make efficiency a number 1 priority to you. in this case, the above script needs to be translated to perl, just because of the culture of the environment here. perl is all they know. so yeah. there's really nothing i have to solve. awk has been more than enough for me in the past. if things really need to get really fancy, then php to the rescue.
# 7  
Old 01-22-2014
The less an author knows, the longer, more fragile and more complicated the script. This problem might be withing the reach of bash or ksh, if the problem and tool are both clearly understood.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Programming

PERL: In a perl-scripttTrying to execute another perl-script that SETS SOME VARIABLES !

I have reviewed many examples on-line about running another process (either PERL or shell command or a program), but do not find any usefull for my needs way. (Reviewed and not useful the system(), 'back ticks', exec() and open()) I would like to run another PERL-script from first one, not... (1 Reply)
Discussion started by: alex_5161
1 Replies

2. Shell Programming and Scripting

Portable way of translating epoch time

echo $(date +%s) | awk '{ print strftime("%c", $2"-"$3"-"$NF"/"$4); }' The above command only seems to work on newer versions of awk or systems with gawk installed. how can i translate the epoch time into a human readable format using a portable method? also, date -d@$epochtime does not... (3 Replies)
Discussion started by: SkySmart
3 Replies

3. Shell Programming and Scripting

Please help translating this to shell

Hello Im new here, I just got my first VPS and I really need help converting this .bat to shell script so i can run my program. @echo off @title DiamondMS v117 set CLASSPATH=.;dist\* java -client -Dnet.sf.odinms.wzpath=wz server.Start pause I have no idea what im doing to convert this... (12 Replies)
Discussion started by: valleric
12 Replies

4. Shell Programming and Scripting

calling a perl script with arguments from a parent perl script

I am trying to run a perl script which needs input arguments from a parent perl script, but doesn't seem to work. Appreciate your help in this regard. From parent.pl $input1=123; $input2=abc; I tried calling it with system("/usr/bin/perl child.pl $input1 $input2"); and `perl... (1 Reply)
Discussion started by: grajp002
1 Replies

5. UNIX for Dummies Questions & Answers

translating physical/virtual addresses

Hi all, I am new to Linux kernel/user space programming having been an assembly programmer in my previous life. I am now using 2.6.x kernel on an embedded CPU that has a few dedicated hardware blocks (including more CPU running just C-code, i.e., no operating system). There is a single DRAM... (1 Reply)
Discussion started by: agaurav
1 Replies

6. UNIX for Dummies Questions & Answers

Translating the same file

I want to strip off '\032' character from a file using: tr -d '\032' < oldfile > newfile this outputs the contents of oldfile to newfile, but I wanna do that in the same file i.e. remove the \032 character from the old file. I tried: tr -d '\032' < oldfile > oldfile But the... (3 Replies)
Discussion started by: gagan8877
3 Replies

7. Shell Programming and Scripting

Translating/Replacing characters in a file

Hi, i have a given file named hugo.dat. In this file there are several lines that contain characters like } and ~ Now, i need a script that replaces the character } to ü and character ~ to ß Can anyone help for a working ksh script? Kind Regards FranzB (3 Replies)
Discussion started by: FranzB
3 Replies

8. UNIX for Advanced & Expert Users

translating device to filesystem in solaris10

Greetings, I have a oracle database server and i keep getting grid control message Metric=Disk Device Busy (%) Metric Value=98.66 Disk Device=ssd430 Severity=Critical Message=Disk Device ssd430 is 98.66% busy. so I am trying to correlate the ssd430 to the filesystem. I understand this... (3 Replies)
Discussion started by: p4cldba
3 Replies
Login or Register to Ask a Question