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 &quot;$1&quot; in<br>&nbsp; start)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo -n &quot;Starting new-service&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $PERL $SRL_READER daemon<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo &quot;.&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;;<br>&nbsp; stop)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo -n &quot;Stopping new-service&quot;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $PERL $SRL_READER -k<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo &quot;.&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;;
<br><br>&nbsp; *)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo &quot;Usage: /sbin/service srlreader {start|stop}&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 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>&nbsp;/sbin/service srlreader start<br>Starting new-serviceINCOMING FILE BEING RECEIVED<br>Closing File<br>Can&#39;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, &lt;DEV&gt; line 24.
<br>.<br><br>Any ideas as to what I&#39;m doing wrong?&nbsp; 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&nbsp;&nbsp;&nbsp; = &quot;/home/richard/test&quot;;&nbsp;&nbsp;&nbsp; # path to data file<br>my $LOGFILE&nbsp;&nbsp; = &quot;serial_data.log&quot;;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # file name to output to
<br>#my $PORT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = &quot;/dev/ttyD015&quot;;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # port to watch<br>my $PORT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = &quot;/dev/ttyS0&quot;;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # port to watch&nbsp; <br><br>#<br># Serial Settings<br>#<br><br>my $ob = Device::SerialPort-&gt;new ($PORT) || die &quot;Can&#39;t Open $PORT: $!&quot;;
<br><br>#<br># open the logfile, and Port<br>#<br><br>open(LOG,&quot;&gt;&gt;${LOGDIR}/${LOGFILE}&quot;)<br>&nbsp;&nbsp;&nbsp; ||die &quot;can&#39;t open smdr file $LOGDIR/$LOGFILE for append: $!\n&quot;;<br><br>open(DEV, &quot;&lt;$PORT&quot;) || die &quot;Cannot open $PORT: $_&quot;;
<br>#open(DEV, &quot;&lt;test_FILEEEEEE&quot;); # if you want to test the prog. from a file<br><br>#select(LOG), $| = 1;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # set nonbufferd mode<br><br>#<br># Loop forver, logging data to the log file<br>#<br><br>my $write_file;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # y or no write data to file
<br>my $mail_count = 0;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # the number of mails received in the session<br>my $filename;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # what the new file will be called<br><br>while($_ = &lt;DEV&gt;) {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # 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>&nbsp; #print $_;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # print to console (for now)<br>&nbsp; print LOG $_;&nbsp;&nbsp;&nbsp; # print to log file
<br><br>if ($_ =~ /#######/) {<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #this is the begining of an email file<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &quot;INCOMING FILE BEING RECEIVED\n&quot;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $mail_count++;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $write_file = &quot;y&quot;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $filename = $mail_count . &quot;EMAIL&quot; . $date; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; open(EMAIL_FILE, &quot;&gt;$filename&quot;) || die &quot;CANT OPEN EMAIL_FILE: $!\n&quot;; <br>&nbsp; <br>}<br><br>if ($write_file eq &quot;y&quot;) {<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print EMAIL_FILE $_;<br><br>} #end of if<br><br><br>

if ($_ =~ /!!!!!!!/) {<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &quot;Closing File\n&quot;; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; close (EMAIL_FILE) || die &quot;CAN&#39;T CLOSE EMAIL_FILE: $!&quot;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $write_file = &quot;n&quot;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; require &quot;mail_processor.pl&quot;;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; process($filename);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rename &quot;$filename&quot;, &quot;sent/$filename&quot;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>} #end of if<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>} # end of while<br><br>undef $ob;<br><br>### end<br></div>