On Tue, 17 Sep 2002, larry lefthook wrote: > Hi! I have modified gsmcontrol.pl (yty.net) as contrologo.pl. & I wonder why > my script is not run by crontab when it works when I run it by hand. I have > a file for the script in /var/gsm/in and when I run contrologo.pl from > commandline it sends sms message (logo) using external program (gnokii) & > moves it to /var/gsm/in.handled. But when the script is run by cron (all one > line): > 2,7,13,17,22,27,32,37,42,47,52,57 * * * * /usr/local/bin/contrologo.pl > 2>/dev/null > it only moves it to the /var/gsm/in.handled, but does not use gnokii for > sending. Do the contrologo.pl exit & stop after tried once external program > or can it somehow reply to all messages in if there is? What I need to add? > > #!/usr/bin/perl -w > > # program reads messages from "sms-inbox"-folder and handles them when > # necessary > #use strict;
Any reason why you have commented out 'use strict' > my $inbox = "/var/gsm/in"; > my $handled = "/var/gsm/in.handled/"; > my $file=""; > my $sendsms = "/usr/local/bin/sendsms.pl"; > my $gnokii = "/usr/local/bin/gnokii"; > my $remove=0; > > #for $file (glob "$inbox/*.txt" ) { > for $file ( <$inbox/*.txt> ) { > my $sender=""; > my $remove=0; > open FILE, $file or die "Cannot open file ($file): $!"; > while (<FILE>) { > if (/Sender:/) { > s/.*Sender:/Sender:/; > ($tmp,$sender,@tmp) = split (" ",$_); By default split works with the contents of $_, you can write this statement as ($tmp,$sender,@tmp) = split (" "); > chomp($sender); > $sender =~ s/\+//g; > $sender =~ s/ //g; The above statement is superfluous. You are getting $sender as result of splitting $_ with spaces. > } > > if (/^GET/) { # ohjausdataa ... > &getlogo($sender,$_); > $remove=1; > } > } > close FILE; > if ($remove == 1) { > `mv $file $handled`; Use backticks only when you are interested in the output of the command, if you are not use system. If you use them also check $? for error. Even better avoid backticks and system if possible. This can be done using the rename function of perl perldoc -f rename > #if ( $remove ) { > #system( 'mv', $file, $handled ) == 0 or warn "Cannot move > # $file: $?"; > } > } > > sub getlogo { > # sauna($sender, $line); > my $sender = $_[0]; > my $line = $_[1]; > > if ($line =~ /KUKAT/) { > my $logo = "/var/gsm/logos/kukat.nol"; > $sender =~ s/358/0/; > #exec "gnokii --sendlogo op $sender $logo 244-05"; > # Tutki which Operator > if ($sender =~ /^050/) { > system "gnokii --sendlogo op $sender $logo 244-05"; This is a PATH issue, why don't you give the entire path to gnokii in this system call. Also for this kind of an application maintain a log file if possible. In this case check the $? variable, if it is not 0 open a log file and write the error into it. Will help you in debugging. > > } > elsif ($sender =~ /^040/) { > system "gnokii --sendlogo op $sender $logo 244-91"; > } > } > } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]