Hello Monks,

here is my script for performing actions on files in a folder based on their names.I have a few questions reg that.most of the actions are performed on a pdf copy of the file but just one chooses the ascii version.I need a method to clean up the files in the folder after all the actions are performed. There may be multiple actions for each file.

#!usr/bin/perl -w use DBI; use File::Copy; @files=<H:/what_to_do/*>; foreach my $file (@files){ my @arr=split(/\//,$file); print "\n"; my @field=split(/%/,$arr[2]); print $arr[2]; my $length_arr=length($arr[2]); my $fname=substr($arr[2],0,($length_arr-4)); print "\n$fname"; my $sysacc=$field[0]; my $rid=$field[2]; my $jid=$field[1]; my $oldloc=$file; my $key=$sysacc."%".$jid."%".$rid; print "\n\nLOOKING UP KEY: $key \n"; $dbh =DBI->connect("dbi:Oracle:host=abc123;sid=test","scott","tiger!") + or die "cannot connect to oracle"; $dbh->{AutoCommit}=0; my $query= "select * from lookup where name_key=\'$key\'"; my $sth=$dbh->prepare($query) or die "prepare failed"; $sth->execute() or die "execute failed"; my $status=0; while(@row=$sth->fetchrow_array()){ $status=1; $print=$row[1]; $not_print=$row[2]; $action1=$row[3]; $action2=$row[4]; $action3=$row[5]; $action4=$row[6]; } $sth->finish(); $dbh->disconnect(); if($status==0){ print "\nFile moved to print\n"; } else{ if( $action4 eq "yes"){ $newloc="h:/HOT/TO BE PROCESSED/$arr[2]"; move($oldloc,$newloc)or die "fail to move"; } my $asciiloc="h:/Ascii/$fname.txt"; print "\n\n$asciiloc\n"; if ($action2 eq "yes"){ $newloc="h:/HOT/cold/$arr[2]"; move($asciiloc,$newloc)or die "fail to move"; } elsif ($action1 eq "yes"){ $newloc="h:/HOT/action2/$arr[2]"; copy($oldloc,$newloc)or die "fail to move"; } if ($action3 eq "yes"){ $newloc="h:/HOT/action3/$arr[2]"; copy($oldloc,$newloc)or die "fail to move"; } if( $not_print eq "yes"){ $newloc="h:/HOT/not_print/$arr[2]"; move($oldloc,$newloc)or die "fail to move"; print "\n+---------------------+\n Moved file to Not print folder \n+- +--------------------+\n"; } if( $print eq "yes"){ $newloc="h:/HOT/print/$arr[2]"; move($oldloc,$newloc)or die "fail to move"; print "\n+---------------------+\n Moved file to print \n+------------ +---------+\n"; } } }
Also I am trying to figure out how to make it run forever in the background and give logging functionality ie i need the date time that each action was performed.The server is a windows server.

Any help would be appreciated.Thank you monks -Smanicka

UPDATE: I found out how to get the loacl time : http://perl.about.com/od/perltutorials/a/perllocaltime_2.htm

In reply to actions lookup ,need help automating by smanicka

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.