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:
<br><br>#! /bin/sh<br># Basic support for *nix style chkconfig<br>###<br># chkconfig: 235 98 55<br># description: Manages the services you are controlling with the chkconfig command<br>###<br><br>PERL=/usr/bin/perl<br>SRL_READER=/usr/src/maillaundpa
<div id="1fjv" class="ArwC7c ckChnd">d/serial_reader_test.pl
<br><br><br>case "$1" in<br> start)<br> echo -n "Starting new-service"<br> $PERL $SRL_READER daemon<br> echo "."<br> ;;<br> stop)<br> echo -n "Stopping new-service"
<br> $PERL $SRL_READER -k<br> echo "."<br> ;;
<br><br> *)<br> echo "Usage: /sbin/service srlreader {start|stop}"<br> exit 1<br>esac<br><br>When I run via the /init.d/script it crashes when it has to call another perl script with the following output:
<br><br> /sbin/service srlreader start<br>Starting new-serviceINCOMING FILE BEING RECEIVED<br>Closing File<br>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.
<br>.<br><br>Any ideas as to what I'm doing wrong? Thanks for any help.<br><br>######### script ########################<br><br>#!/usr/bin/perl -w<br># serial_reader_test.pl<br>#test this program w/out serial drives
<br>
<br>use strict;<br>use Device::SerialPort;<br><br>my $LOGDIR = "/home/richard/test"; # path to data file<br>my $LOGFILE = "serial_data.log"; # file name to output to
<br>#my $PORT = "/dev/ttyD015"; # port to watch<br>my $PORT = "/dev/ttyS0"; # port to watch <br><br>#<br># Serial Settings<br>#<br><br>my $ob = Device::SerialPort->new ($PORT) || die "Can't Open $PORT: $!";
<br><br>#<br># open the logfile, and Port<br>#<br><br>open(LOG,">>${LOGDIR}/${LOGFILE}")<br> ||die "can't open smdr file $LOGDIR/$LOGFILE for append: $!\n";<br><br>open(DEV, "<$PORT") || die "Cannot open $PORT: $_";
<br>#open(DEV, "<test_FILEEEEEE"); # if you want to test the prog. from a file<br><br>#select(LOG), $| = 1; # set nonbufferd mode<br><br>#<br># Loop forver, logging data to the log file<br>#<br><br>my $write_file; # y or no write data to file
<br>my $mail_count = 0; # the number of mails received in the session<br>my $filename; # what the new file will be called<br><br>while($_ = <DEV>) { # print input device to file<br><br># get a nice date string for naming an email file
<br>my ($yr, $mo, $day, $hr, $min, $sec) = (localtime)[5,4,3,2,1,0];<br>my $date = $sec . $min . $hr . $day . ($mo + 1) . ($yr + 1900);<br><br> #print $_; # print to console (for now)<br> print LOG $_; # print to log file
<br><br>if ($_ =~ /#######/) {<br><br> #this is the begining of an email file<br> print "INCOMING FILE BEING RECEIVED\n";<br> $mail_count++;<br> $write_file = "y";<br> $filename = $mail_count . "EMAIL" . $date;
<br> open(EMAIL_FILE, ">$filename") || die "CANT OPEN EMAIL_FILE: $!\n"; <br> <br>}<br><br>if ($write_file eq "y") {<br><br> print EMAIL_FILE $_;<br><br>} #end of if<br><br><br>
if ($_ =~ /!!!!!!!/) {<br><br> print "Closing File\n"; <br> close (EMAIL_FILE) || die "CAN'T CLOSE EMAIL_FILE: $!";<br> $write_file = "n";<br> require "mail_processor.pl";
<br> process($filename);<br> rename "$filename", "sent/$filename";<br> <br>} #end of if<br> <br>} # end of while<br><br>undef $ob;<br><br>### end<br></div>