Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
Please Help on Perl Scripting.

Posted by Laarni (Laarni), 10 January 2008
Hi,

Im going to convert a big cshell script to Perl. Haven't done any perl script before anyone can please help me on this?

Thanks in advance.


if ( !(-f PROMOTE_CFG.`hostname`.fil) || !(-f PROMOTE.cfg) ) then
       echo ""
       echo "Please run this script in the same directory as this script in this server [`hostname`]"
       echo ""
       exit 1
endif

source PROMOTE.cfg

set startime = `date`

echo $0
echo ""
echo "------------------------------------------"
echo ""
echo "Creating log directory..."$log
if !(-d $conv) mkdir $conv
if !(-d $log) mkdir $log

if (-f PROMOTE_CFG.`hostname`.fil) then
       set dbfilelist = "PROMOTE_CFG.`hostname`.fil"
       set dblist = `cat $dbfilelist`
else
       echo ""
       echo "Please list the databases to be converted in PROMOTE_CFG.`hostname`.fil"
       echo ""
       exit 1
endif

# Perform the Database promotion only once

if ((`ls PROMOTE_CFG.*pap.fil | wc -l` > 1) && ($HOST2CHK4DBPROMOTE != `hostname`)) then
       echo ""
       echo "Database promotion will not be executed at this server [`hostname`]"
       echo ""
       exit 1
endif

# Begin converting the Database
foreach line ($dblist)

set site = `echo $line | cut -f1 -d:`
set db = `echo $line | cut -f2 -d:`

#check site config file
if !( -f cfg/$site.`hostname`.cfg ) then
       echo ""
       echo "Please check configuration for site cfg/$site.`hostname`.cfg exists"
       echo ""
       source PROMOTE.uncfg
       exit 1
endif

echo ""
echo "$db ($site) database conversion..."

# Set the DB, UID, PSW and SVR based on site
sed -e s/db_name/$db/g cfg/$site.`hostname`.cfg >! $cfg/$db.cfg

if !(-f $cfg/$db.cfg) then
       echo ""
       echo "Please check if the configuration file for database $cfg.$db.cfg exists"
       echo ""
       source PROMOTE.uncfg
       exit 0
endif

source $cfg/$db.cfg

if !(-d $backup_dat/$db) then
       echo ""
       echo "Create backup directory [$backup_dat/$db] for database..."$db
       mkdir $backup_dat/$db
endif

if (-f new_table_list.fil) then
       echo ""
       echo "Creating new tables..."
       set newtablist = `cat new_table_list.fil`
       set table_no = 0
       echo "New table creation log:" >! $log/newtable_$db.log
       foreach table ($newtablist)
               set table_no = `expr $table_no + 1`
               echo $table_no") "$table
               echo $table_no") "$table >> $log/newtable_$db.log
               if (-f $newtabdir/$table) then
                       runsql < $newtabdir/$table >> $log/newtable_$db.log
               else
                       if (-f $alt1tabdir/$table) then
                               runsql < $alt1tabdir/$table >> $log/newtable_$db.log
                       else
                               if (-f $alt2tabdir/$table) then
                                       runsql < $alt2tabdir/$table >> $log/newtable_$db.log
                               else
                                       if (-f $alt3tabdir/$table) then
                                               runsql < $alt3tabdir/$table >> $log/newtable_$db.log
                                       else
                                               if (-f $alt4tabdir/$table) then
                                                       runsql < $alt4tabdir/$table >> $log/newtable_$db.log
                                               else
                                                       if (-f $alt5tabdir/$table) then
                                                               runsql < $alt5tabdir/$table >> $log/newtable_$db.log
                                                       else
                                                               runsql < $alt6tabdir/$table >> $log/newtable_$db.log
                                                       endif
                                               endif
                                       endif
                               endif
        endif
               endif
               echo "" >> $log/newtable_$db.log
       end
endif
if (-f stored_proc_list.fil) then
       echo ""
       echo "Submitting stored procedures..."
       set storedproclist = `cat stored_proc_list.fil`
       set script_no = 0
       echo "Stored Procedure creation log:" >! $log/storedproc_$db.log
       foreach script ($storedproclist)
               set script_no = `expr $script_no + 1`
               echo $script_no") "$script
               echo $script_no") "$script >> $log/storedproc_$db.log
               if (-f $sqlprocdir/$script) then
                       runsql < $sqlprocdir/$script >> $log/storedproc_$db.log
               else
                       if (-f $alt1sqlprocdir/$script) then
                               runsql < $alt1sqlprocdir/$script >> $log/storedproc_$db.log
                       else
                               if (-f $alt2sqlprocdir/$script) then
                                       runsql < $alt2sqlprocdir/$script >> $log/storedproc_$db.log
                               else
                                       runsql < $alt3sqlprocdir/$script >> $log/storedproc_$db.log
                               endif
                       endif
               endif
               echo "" >> $log/storedproc_$db.log
       end
endif

# move to the bottom
if (-f trigger_list.fil) then
       echo ""
       echo "Submitting trigger..."
       set triggerlist = `cat trigger_list.fil`
       set table_no = 0
       echo "Trigger creation log:" >! $log/trigger_$db.log
       foreach table ($triggerlist)
               set table_no = `expr $table_no + 1`
               echo $table_no") "$table
               echo $table_no") "$table >> $log/trigger_$db.log
               if (-f $newtabdir/$table) then
                       runsql < $newtabdir/$table >> $log/trigger_$db.log
               else
                       if (-f $alt1tabdir/$table) then
         runsql < $alt1tabdir/$table >> $log/trigger_$db.log
                       else
                               runsql < $alt2tabdir/$table >> $log/trigger_$db.log
                       endif
               endif
               echo "" >> $log/trigger_$db.log
       end
endif


# grant privilege
echo ""
echo "grant privilege"
cat update/gen_grant.sql | runsql | egrep '^ grant|^ go' | cut -c2- | runsql >>! $log/onetime_grant_$db.log

echo ""
echo "Completed $db database conversion..."

end
#end of the main for loop

#############################
if (-f jil.fil) then

       # set environment for autosys
       source $autosysdir

       echo ""
       echo "Submitting Autosys jobs ..."
       set joblists = `cat jil.fil`
       set job_no=0
       echo "Autosys jobs log:" >! $log/jobs.log
       foreach joblist ($joblists)
               set job_no = `expr $job_no + 1`
               echo $job_no") "$joblist
               echo $job_no") "$joblist >> $log/jobs.log
               #backup
               set job=`echo $joblist | cut -f1 -d'.'`
               autorep -q -J $job -L0 >! $backup_jil/$job.bak
                               #punch in job
               jil < misc/jil/$joblist >>! $log/jobs.log
       end
endif


source PROMOTE.uncfg

echo ""
echo "------------------------------------------"
echo ""
echo Start time = $startime
echo Stop time  = `date`
echo ""

if (-f readme.txt) cat readme.txt


Posted by admin (Graham Ellis), 10 January 2008
on 01/10/08 at 08:54:11, Laarni wrote:
Hi,

Im going to convert a big cshell script to Perl. Haven't done any perl script before anyone can please help me on this?



Sure, be delighted to ... but it's a bit more of a project than the sort of thing that can be done as an answer on a forum.  Follow the link to:

http://www.wellho.net/course/ppfull.html

I'm running this next week; book, come along, bring your shell script and you'll be well on the way by Friday!

-- Graham



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho