tannx has asked for the wisdom of the Perl Monks concerning the following question:

I wrote script that edits data and then loads it into database. Under Unix environment it works but under linux(centos 4.6) load to database does not work.
#!/usr/bin/perl -w use POSIX qw(strftime); $in_dir = '/home/data'; $out_dir = '/var/www/html/rwa_test/input'; $zip_dir = '/home/data/archive'; $kpva = strftime("%Y%m%d", localtime); $wait = 30; while (0 < 1) { system ("ls -htr $in_dir/*.P.M > $in_dir/failid.rwa "); sleep 30; open(TF, "$in_dir/failid.rwa"); while (<TF>) { chomp; print $_,"\n"; s|$in_dir/||; print $_,"\n"; $ifn = $_; system("gzip -f <$in_dir/$ifn >$zip_dir/$ifn.$kpva.gz" +); open(IF,"$in_dir/$ifn"); open(OF,">$out_dir/$ifn.$kpva"); while(<IF>) { chomp; $line = $_; last if $line =~ /^-{19}/; $line =~ s/,/./g; $line =~ s/\t/;/g; print OF $line,"\n"; } close (IF); close (OF); $cmd = "dbisqlc -c ".'"uid=.....;pwd=.....;eng=......;dbn=...... "'." +-q call ......Fun_LoadAllFiles( '"."$out_dir/$ifn.$kpva', '$ifn.$kpva +')"; print $cmd,"\n"; system (@cmd); system("mv -f $in_dir/$ifn $in_dir/$ifn.done"); } close(TF); sleep $wait; }
why does this part not under linux work?
$cmd = "dbisqlc -c ".'"uid=****;pwd=****;eng=****;dbn=**** "'." -q cal +l ****.Fun_LoadAllFiles( '"."$out_dir/$ifn.$kpva', '$ifn.$kpva')";
added print $cmd and it shows as it should <code> dbisqlc -c "uid=****;pwd=*****;eng=*****;dbn=***** " -q call ****.Fun_LoadAllFiles( '/var/www/html/rwa_test/input/file_name', 'file_name')

Replies are listed 'Best First'.
Re: unable execute $cmd
by BrowserUk (Patriarch) on Oct 20, 2008 at 08:14 UTC
Re: unable execute $cmd
by jwkrahn (Abbot) on Oct 20, 2008 at 11:16 UTC

    You don't have any error checking so that would probably be better written as:

    #!/usr/bin/perl use warnings; use strict; use POSIX qw(strftime); use File::Basename; my $in_dir = '/home/data'; my $out_dir = '/var/www/html/rwa_test/input'; my $zip_dir = '/home/data/archive'; my $kpva = strftime '%Y%m%d', localtime; my $wait = 30; { for my $ifn ( sort { -M $b <=> -M $a } <$in_dir/*.P.M> ) { print "$ifn\n"; $ifn = basename $ifn; print "$ifn\n"; { open my $IN, '-|', 'gzip', '-c', "$in_dir/$ifn" or die "Ca +nnot open pipe from gzip: $!"; open my $ZIP, '>:raw', "$zip_dir/$ifn.$kpva.gz" or die "Ca +nnot open '$zip_dir/$ifn.$kpva.gz' $!"; local $/ = \4096; print $ZIP $_ while <$IN>; close $IN or warn $! ? "Error closing gzip pipe: $!" : "Exit status $? from gzip"; } open my $IF, '<', "$in_dir/$ifn" or die "Cannot open '$in_dir/ +$ifn' $!"; open my $OF, '>', "$out_dir/$ifn.$kpva" or die "Cannot open '$ +out_dir/$ifn.$kpva' $!"; while ( <$IF> ) { last if /^-{19}/; tr/,\t/.;/; print $OF $_; } my $cmd = qq[dbisqlc -c "uid=.....;pwd=.....;eng=......;dbn=.. +.... " -q call ......Fun_LoadAllFiles( '$out_dir/$ifn.$kpva', '$ifn.$ +kpva')]; print "$cmd\n"; 0 == system $cmd or die "system $cmd failed: $?"; rename "$in_dir/$ifn", "$in_dir/$ifn.done" or die "Cannot rena +me '$in_dir/$ifn' $!"; } sleep $wait and redo; }
Re: unable execute $cmd
by tannx (Acolyte) on Oct 20, 2008 at 09:15 UTC
    Thank you. Found and corrected my typo. Case closed.
      Not so fast. How did you get it to work correctly on a different platform, as you claim in the top of your post? It's not that on non-Linux Unix platforms there isn't a difference between $cmd and @cmd.
      See what you get for abandoning strict? Don't do that! :)