[sf-perl] Running a perl script as a service
Richard Reina
gatorreina at gmail.com
Fri Jan 11 07:39:27 PST 2008
I have a script below (at the bottom ) that reads incoming data from serial
port and formats it. The program works fine when I execute it from a
console. However, in order to keep it up at all times I created an
/etc/init.d script that executes it:
#! /bin/sh
# Basic support for *nix style chkconfig
###
# chkconfig: 235 98 55
# description: Manages the services you are controlling with the chkconfig
command
###
PERL=/usr/bin/perl
SRL_READER=/usr/src/maillaundpad/serial_reader_test.pl
case "$1" in
start)
echo -n "Starting new-service"
$PERL $SRL_READER daemon
echo "."
;;
stop)
echo -n "Stopping new-service"
$PERL $SRL_READER -k
echo "."
;;
*)
echo "Usage: /sbin/service srlreader {start|stop}"
exit 1
esac
When I run via the /init.d/script it crashes when it has to call another
perl script with the following output:
/sbin/service srlreader start
Starting new-serviceINCOMING FILE BEING RECEIVED
Closing File
Can't locate mail_processor.pl in @INC (@INC contains:
/usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi
/usr/lib/perl5/site_perl/5.8.7/i386-linux-thread-multi
/usr/lib/perl5/site_perl/5.8.6/i386-linux-thread-multi
/usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi
/usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl/5.8.7
/usr/lib/perl5/site_perl/5.8.6 /usr/lib/perl5/site_perl/5.8.5
/usr/lib/perl5/site_perl
/usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi
/usr/lib/perl5/vendor_perl/5.8.7/i386-linux-thread-multi
/usr/lib/perl5/vendor_perl/5.8.6/i386-linux-thread-multi
/usr/lib/perl5/vendor_perl/5.8.5/i386-linux-thread-multi
/usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl/5.8.7
/usr/lib/perl5/vendor_perl/5.8.6 /usr/lib/perl5/vendor_perl/5.8.5
/usr/lib/perl5/vendor_perl /usr/lib/perl5/5.8.8/i386-linux-thread-multi
/usr/lib/perl5/5.8.8 .) at /usr/src/maillaundpad/serial_reader_test.pl line
71, <DEV> line 24.
.
Any ideas as to what I'm doing wrong? Thanks for any help.
######### script ########################
#!/usr/bin/perl -w
# serial_reader_test.pl
#test this program w/out serial drives
use strict;
use Device::SerialPort;
my $LOGDIR = "/home/richard/test"; # path to data file
my $LOGFILE = "serial_data.log"; # file name to output to
#my $PORT = "/dev/ttyD015"; # port to watch
my $PORT = "/dev/ttyS0"; # port to watch
#
# Serial Settings
#
my $ob = Device::SerialPort->new ($PORT) || die "Can't Open $PORT: $!";
#
# open the logfile, and Port
#
open(LOG,">>${LOGDIR}/${LOGFILE}")
||die "can't open smdr file $LOGDIR/$LOGFILE for append: $!\n";
open(DEV, "<$PORT") || die "Cannot open $PORT: $_";
#open(DEV, "<test_FILEEEEEE"); # if you want to test the prog. from a file
#select(LOG), $| = 1; # set nonbufferd mode
#
# Loop forver, logging data to the log file
#
my $write_file; # y or no write data to file
my $mail_count = 0; # the number of mails received in the session
my $filename; # what the new file will be called
while($_ = <DEV>) { # print input device to file
# get a nice date string for naming an email file
my ($yr, $mo, $day, $hr, $min, $sec) = (localtime)[5,4,3,2,1,0];
my $date = $sec . $min . $hr . $day . ($mo + 1) . ($yr + 1900);
#print $_; # print to console (for now)
print LOG $_; # print to log file
if ($_ =~ /#######/) {
#this is the begining of an email file
print "INCOMING FILE BEING RECEIVED\n";
$mail_count++;
$write_file = "y";
$filename = $mail_count . "EMAIL" . $date;
open(EMAIL_FILE, ">$filename") || die "CANT OPEN EMAIL_FILE: $!\n";
}
if ($write_file eq "y") {
print EMAIL_FILE $_;
} #end of if
if ($_ =~ /!!!!!!!/) {
print "Closing File\n";
close (EMAIL_FILE) || die "CAN'T CLOSE EMAIL_FILE: $!";
$write_file = "n";
require "mail_processor.pl";
process($filename);
rename "$filename", "sent/$filename";
} #end of if
} # end of while
undef $ob;
### end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/sanfrancisco-pm/attachments/20080111/774deb2e/attachment.html
More information about the SanFrancisco-pm
mailing list