The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Problem: Run schedular to copy from one table to other nehagupta2008 UNIX for Dummies Questions & Answers 0 06-02-2008 09:58 AM
upload oracle table swapnil286 HP-UX 2 01-04-2007 03:37 AM
Upload of the images from the folder to the Database table shashisaini24 UNIX for Advanced & Expert Users 0 11-29-2006 06:03 AM
lookup table in perl?? Bhups Shell Programming and Scripting 2 11-06-2006 10:35 AM
stuck in perl cgi to upload a file to server sachin_kaw Shell Programming and Scripting 4 06-26-2005 09:36 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-01-2006
maheshsri maheshsri is offline
Registered User
  
 

Join Date: Oct 2005
Posts: 31
Perl sql table upload variable problem

Hi,

I wrote a perl script to create and upload data to a mysql data base. Please see the script as shown below,
Code:
#!/usr/bin/perl -w

#Defenetion of modules use in this scrpt
use CGI qw(:standard);
use DBI ;


my $datetable1 = `date +%Y%m%d`;
my $datetable = $datetable1 ;
print ${datetable} ;                                                                                                         
# set the data source name
# format: dbi:db type:db name:host:port
# mysqls default port is 3306
# if you are running mysql on another host or port,
#you must change it                                                                                                                                                                                                                                       
my $dsn = 'dbi:mysql:ppscdr:localhost:3306';

# set the user and password

my $user = 'perl';
my $pass = 'perl';                                                                                                           
# now connect and get a database handle

  my $dbh = DBI->connect($dsn, $user, $pass)
            or die "Cant connect to the DB: $DBI::errstr\n";

my $sth_rec = $dbh->prepare("CREATE TABLE rec_$datetable (CallType  CHAR(1) NOT NULL, CallingPartyNumber
                             CHAR(32) NOT NULL, CalledPartyNumber CHAR(32) NOT NULL, CallBeginTime CHAR(14) NOT NULL,
                             CallDuration int(8) NOT NULL, NormalFee int(8) NOT NULL,
                             NormaAccountBalanceAfterCall int(8) NOT NULL)");

    $sth_rec->execute;

    my $sth1_rec_u = $dbh->prepare("LOAD DATA INFILE '/ppscdr/cdrrec/combined/$datetable.cdrrec.txt'
                              INTO TABLE rec_$datetable FIELDS TERMINATED BY '|'");

    $sth1_rec_u->execute;


my $sth_smr = $dbh->prepare("CREATE TABLE smr_$datetable (CallingPartyNumber CHAR(32) NOT NULL,
                         CalledPartyNumber CHAR(32) NOT NULL, FeeDiductionType int(1) NOT NULL,
                         NormalFee int(8) NOT NULL, SmsDateTime CHAR(14) NOT NULL,
                         NormaAccountBalanceAfterSMS int(8) NOT NULL)");

    $sth_smr->execute;

    my $sth_smr_u = $dbh->prepare("LOAD DATA INFILE '/ppscdr/cdrsmr/combined/$datetable.cdrsmr.txt'
                              INTO TABLE smr_$datetable FIELDS TERMINATED BY '|'");

    $sth_smr_u->execute;

my $sth_p2p = $dbh->prepare("CREATE TABLE p2p_$datetable (CallingPartyNumber CHAR(32) NOT NULL,
                         CalledPartyNumber CHAR(32) NOT NULL,
                         TransferDateTime CHAR(14) NOT NULL, TransferBalance int(16) NOT NULL,
                         SubCosIDsnd int(8) NOT NULL, SubCosIDrsv int(8) NOT NULL,
                         TransferFee int(16) NOT NULL)");

    $sth_p2p->execute;

    my $sth_p2p_u = $dbh->prepare("LOAD DATA INFILE '/ppscdr/cdrp2p/combined/${datetable}.cdrp2p.txt'
                              INTO TABLE p2p_$datetable FIELDS TERMINATED BY '|'");

    $sth_p2p_u->execute;
It giving following error, please sombody tell me how can i resolve this error,

Code:
./auto_sql_upload.pl
20061201
DBD::mysql::st execute failed: Can't get stat of '/ppscdr/cdrrec/combined/20061201
.cdrrec.txt' (Errcode: 2) at ./auto_sql_upload.pl line 37.
DBD::mysql::st execute failed: Can't get stat of '/ppscdr/cdrsmr/combined/20061201
.cdrsmr.txt' (Errcode: 2) at ./auto_sql_upload.pl line 50.
DBD::mysql::st execute failed: Can't get stat of '/ppscdr/cdrp2p/combined/20061201
.cdrp2p.txt' (Errcode: 2) at ./auto_sql_upload.pl line 63. :mad:
  #2 (permalink)  
Old 12-01-2006
nathan nathan is offline VIP Member  
Supporter
  
 

Join Date: Jul 2006
Posts: 156
You need to chomp your date variable. It's looking for a file with a newline character in it. Add the line below in red.

Code:
my $datetable1 = `date +%Y%m%d`;
chomp $datetable1;
my $datetable = $datetable1 ;
print ${datetable} ;
Whenever you execute a shell command from Perl, it will most likely have the newline character attached to the output.
  #3 (permalink)  
Old 12-01-2006
maheshsri maheshsri is offline
Registered User
  
 

Join Date: Oct 2005
Posts: 31
Thanks for the support. Scrip is working fine after modification done according to your advice.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:45 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0