?
Solved

Convert Korn Shell script to Perl?

Posted on 2003-02-19
3
Medium Priority
?
1,075 Views
Last Modified: 2008-03-04
Hi all,
I have korn shell script, if some script guru can help me to convert this script into purely Perl.
I have little or almost no clue about ksh (very new to scripting as well).
Hope to get some feed back.
Thanks

#########################################################
#!/bin/ksh
#
# GLOBALS FOR MAIL LIST
gModerator="name@\@mail.com"
gCCList="name@\@mail.com"

#
# IF WE WERE INVOKED FROM THE "Submit" BROWSER BUTTON
#
if [[ -n "$QUERY_STRING" ]]
then
    location=${QUERY_STRING#http://*/}
    location=${location%/*}
    LOC=$location
    location="$DOCUMENT_ROOT/$location"
    loginId=${location##*/}
    loginId=${loginId%%.*}

    # REVIEW PAGE COULD BE BLANK, SO SET TO ZERO
    #
    if [ -z "$rPage" ]
    then
        rPage=0
    fi

    # CAN WE MOVE TO THE DIRECTORY?
    if cd $location
    then
        # LOCK IT DOWN
        touch .iccb.lck
        touch .submit.lck

        # LET HTTP PROTOCOL KNOW THAT THIS IS A PLAIN TEXT
        #
        print -- "Content-type: text/html"
        print -- ""
        print -- "<HTML><HEAD><TITLE>Results of Submission Request</TITLE></HEAD><BODY>"
    else
        print -- "Content-type: text/plain"
        print -- ""
        print -- "Couldn't find your review page at '$location'."
        exit 0
    fi
else
    print -u2 -- "This script should only be run from a broswer".

  exit 1
fi

# FIGURE OUT FOR WHICH RELEASE THE SUBMISSION IS MADE
#
set -A paths $(print $location | sed 's+/+ +g')
nbrOfElements=$(( ${#paths[*]} - 2 ))
Release=${paths[$nbrOfElements]}
Release=${Release#?}

# WHICH USER
#
user=$(cut -f2 -d"'" .USER)

# WHICH PAGE?
#
rPage=${PWD#${PWD%?}}
if [ \( "$rPage" != "1" \) -a \( "$rPage" != "2" \) ]
then
    rPage=0
fi

# MANIPULATE ANY CC LLISTS
#
if [ -n "$gCCList" ]
then
    gCCList="-c $gCCList"
fi

# MAIL THE WORK
#
_subject="ICCB review request for the submission title '$(cat .DESC)'"
print "Submitted at $(date)" >> sbmsnLog
/bin/ls *.xsd Examples/*.xml >> sbmsnLog 2> /dev/null
/bin/mailx -s "$_subject" -r "$user" "$gCCList" $gModerator 2>> sbmsnLog <<EOF
To whom it may concern:

$user requests that the feature
"$(cat .DESC)" in release '$Release' be reviewed by the ICCB.
$user submitted this request for Review Page $page.

Best regards,
The ICCB automated submission button.
EOF

# APPEND THE USER INTO THE DATABASE
#
print "$Release|$user|$loginId|$rPage|$(cat .DESC)|pre-ICCB|&nbsp;|&nbsp;|0|0|$(date)|Awaiting Review.|&nbs
p;|$(date)|&nbsp;">>/p2k/cgi-bin/ICCB/Database/reviewList.dat

# NOW PRINT THE RESULTS
print -- ""
if [ $? = 0 ]
then
    print -- "Your request has been transmitted to the ICCB Moderator"
    print -- "$SERVER_ADMIN. You should receive an email from the moderator"
    print -- "within a business day informing you that the moderator has received"
    print -- "your request."
else
    print -- "Your request could not be mailed.  Please send a mail"
    print -- "to Web Master."
fi

cat - <<EOF
        </PRE>
    You may close this page using your browser's controls or by pressing this button:
    <FORM><INPUT TYPE="BUTTON" VALUE="CLOSE" ONCLICK="self.close()"></FORM>
    </BODY>
</HTML>
EOF
0
Comment
Question by:kooldiamond
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 48

Expert Comment

by:Tintin
ID: 7984130
For the CGI parsing, use the standard CGI module

perldoc CGI

For the mail, call sendmail directly, or use one of the mail modules.
0
 

Author Comment

by:kooldiamond
ID: 8008874
Tintin,

One more quick question, I want to have UTC time to stamped, in place of Date(), How can i get UTC in the above script? (In APPEND the User in Database)

Thank you
0
 
LVL 48

Accepted Solution

by:
Tintin earned 150 total points
ID: 8012261
The gmtime function returns the UTC date/time

my $timestamp=gmtime;

or if you want a formatted timestamp, use

use POSIX qw(strftime);
my $timestamp = strftime "%Y%m%d%H%M", gmtime;

In this case, the timestamp will be YYYYMMDDHHMM
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question