Help on Perl Scripting

Help on Perl Scripting

am 10.01.2008 10:06:14 von Laarni

Hi,

Im trying to convert c shell script to PERL but haven't use PERL
before can anybody help me on this? Thanks in advance.


#! /bin/csh

if ($#argv <= 2) then
echo "Usage : $0 "
exit
endif

set table = $argv[1]
set config_file = $argv[2]
set config_file_2 = $argv[3]

source $config_file

if ( $#argv >= 3 ) then
if (-f $config_file_2) then
source $config_file_2
endif
endif

if !(-d $backup) then
echo ""
echo "Create backup directory..."
mkdir $backup
endif

if !(-d $backup/$DB) then
echo ""
echo "Create backup directory for database..."$DB
mkdir $backup/$DB
endif

bcp $DB..$table out $backup/$DB/$table -c -U$UID -P$PSW -S$SVR

echo " Rename table..."
sed -e s/table/$table/g modify_rename_table.sql | runsql

#! /bin/csh

if ($#argv <= 2) then
echo "Usage : $0 "
exit
endif

set table = $argv[1]
set config_file = $argv[2]
set config_file_2 = $argv[3]

source $config_file

if ( $#argv >= 3 ) then
if (-f $config_file_2) then
source $config_file_2
endif
endif

if !(-d $backup) then
echo ""
echo "Create backup directory..."
mkdir $backup
endif

if !(-d $backup/$DB) then
echo ""
echo "Create backup directory for database..."$DB
mkdir $backup/$DB
endif

bcp $DB..$table out $backup/$DB/$table -c -U$UID -P$PSW -S$SVR

echo " Rename table..."
sed -e s/table/$table/g modify_rename_table.sql | runsql

if (-f $table.convert.sql) then
echo " Converting temp table..."
runsql < $table.convert.sql
endif

echo " Recreate table..."
if (-f $newtabdir/$table.tab.sql) then
runsql < $newtabdir/$table.tab.sql
else
if (-f $alt1tabdir/$table.tab.sql) then
runsql < $alt1tabdir/$table.tab.sql
else
if (-f $alt2tabdir/$table.tab.sql) then
runsql < $alt2tabdir/$table.tab.sql
else
if (-f $alt3tabdir/$table.tab.sql) then
runsql < $alt3tabdir/$table.tab.sql
else
if (-f $alt4tabdir/$table.tab.sql) then
runsql < $alt4tabdir/$table.tab.sql
else
if (-f $alt5tabdir/$table.tab.sql) then
runsql < $alt5tabdir/
$table.tab.sql
endif
endif
endif
endif
endif
endif

echo " Copy data..."
if (-f $table.copy.sql) then
runsql < $table.copy.sql
else
if (-f $table.select.sql) then
sed -e s/table/$table/g modify_copy_data.sql | sed -e s/\*/`cat
$table.select.sql`/g | runsql
else
sed -e s/table/$table/g modify_copy_data.sql | runsql
endif
endif

echo " Drop temp table..."
runsql < modify_drop_temp.sql

source ../PROMOTE.uncfg

Regards,
Laarni

Re: Help on Perl Scripting

am 10.01.2008 10:35:53 von Gunnar Hjalmarsson

Laarni wrote:
> Im trying to convert c shell script to PERL but haven't use PERL
> before can anybody help me on this?

Sure. http://learn.perl.org/

> Thanks in advance.

You're welcome.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Re: Help on Perl Scripting

am 10.01.2008 19:28:31 von Jim Gibson

In article
<75c28a2e-7b3f-4d1b-907d-c75488098c89@d21g2000prf.googlegroups.com>,
Laarni wrote:

> Hi,
>
> Im trying to convert c shell script to PERL but haven't use PERL
> before can anybody help me on this? Thanks in advance.

Here is some code to get you started. It is all untested and guaranteed
to have mistakes:

>
>
> #! /bin/csh

#!/usr/bin/perl
use strict;
use warnings;

>
> if ($#argv <= 2) then
> echo "Usage : $0 "
> exit
> endif

if( @ARGV <= 2 ) {
print "Usage: $0 \n";
exit;
}

>
> set table = $argv[1]
> set config_file = $argv[2]
> set config_file_2 = $argv[3]

my( $table, $config_file, $config_file_2 ) = @ARGV;

>
> source $config_file

do $config_file or die("Can't do $config_file: $!");

>
> if ( $#argv >= 3 ) then
> if (-f $config_file_2) then
> source $config_file_2
> endif
> endif

if( $config_file_2 ) {
if( -f $config_file_2 ) {
do $config_file_2 or die("Can't do $config_file_2: $!");
}
}

>
> if !(-d $backup) then
> echo ""
> echo "Create backup directory..."
> mkdir $backup
> endif

if( ! -d $backup ) {
mkdir $backup or die("Can't create $backup directory: $!");
}

>
> if !(-d $backup/$DB) then
> echo ""
> echo "Create backup directory for database..."$DB
> mkdir $backup/$DB
> endif

(similar)

>
> bcp $DB..$table out $backup/$DB/$table -c -U$UID -P$PSW -S$SVR

(Where do $UID, $PSW, and $SVR come from? $UID looks like user id and
Perl has built-in $< for that. If $PSW and $SVR are environment
variables, you can get them from the %ENV hash as $ENV{PSW} and
$ENV{SVR}.)

system(" bcp $DB..$table out $backup/$DB/$table -c -U$< -P$ENV{PSW}
-S$ENV{SVR");

>
> echo " Rename table..."
> sed -e s/table/$table/g modify_rename_table.sql | runsql

(read modify_rename_table.sql file, modify, and call system to run
runsql perhaps)


>
> #! /bin/csh

(Are you starting over?)

[rest snipped]

Good luck!

--
Jim Gibson

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com