This is about how to Monitoring folder for new files using shell script
im doing a project using smsserver tools 3. i have used a perl script
to handle incoming messages. the content of each message must be
directed to a java program. this program generates the answer to reply
to the user .so i need to call the java program from the perl code.
this is my perl code
//******************************************************************************************************************************************
#!/usr/bin/perl -w
use strict;
use File::Monitor;
use File::Monitor::Object;
my $number = '';
my $msgFrom = '';
my $outgoing = "/home/T/Documents/run/outgoing/";
my $extract ="/home/T/Documents/run/extract part/";
my $temp = '/var/spool/sms/incoming';
my $monitor = File::Monitor->new();
my $newline = 0;
$monitor->watch( {
name => "$temp",
recurse => 1,
callback => \&Test,
} );
$monitor->scan;
for (my $i=0; $i < 100; $i++)
{
my @changes = $monitor->scan;
sleep 5;
}
sub Test
{
my ($name, $event, $change) = @_;
my @adds = $change->files_created;
my @dels = $change->files_deleted;
if(@adds){
print "Added: ".join("\nAdded: ", $adds[0])."\n"; # if @adds;
my $filename = $adds[0];
open (INFILE, $filename); # if @adds;
while (my $line = <INFILE>) {
chomp $line;
$line = lc($line);
if ($newline == 1) {
$msgFrom = $msgFrom.$line;
printf "*************".$msgFrom;
}
if ($line =~ /^from: (.*)/) {
$number = $1;
} elsif (length($line) == 0) {
$newline = 1;
}
}
close INFILE;
open(OUTFILE1 , ">".$number.".txt");
print OUTFILE1 ("hi gfdg");
close OUTFILE1;
open(OUTFILE, ">".$outgoing."sms".$number."-".int(rand(100000)));
#open for write, overwrite
print OUTFILE ("To: ",$number); #write text without newline
print OUTFILE "\n\n";
print OUTFILE join(',','hi is this working '); #write text
print OUTFILE "\n"; #write newline
close OUTFILE;
}
}
//******************************************************************************************************************************************
can anyone help me to write this perl code in shell script ?
or is there a way to call java programe inside perl code?