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; > 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:/) {
This if statement uses a regular expression to find the string 'Sender:' > s/.*Sender:/Sender:/; Here you use another regular expression to remove everything before the string 'Sender:'. > ($tmp,$sender,@tmp) = split (" ",$_); Here you split the $_ variable on whitespace. This means that split REMOVES every " ", "\n", "\r", "\t" and "\f" character. The variable $tmp now contains the string 'Sender:' and $sender contains the value you want and @tmp contains the rest of the list. If you had not included the @tmp array split() would not have to parse the entire string so you are forcing it to work more than it needs to. Since you are not actually using the variable $tmp you could replace it with undef. This could be written more efficiently as: ( undef, $sender ) = split; > chomp($sender); chomp() removes the value of $/ which is normally set to "\n" from the end of the variable $sender. Since the previous split statement removed all " ", "\n", "\r", "\t" and "\f" characters THERE IS NOTHING FOR chomp TO REMOVE! > $sender =~ s/\+//g; > $sender =~ s/ //g; $sender =~ s/ //g removes the space character (" ") from the variable $sender. Since the previous split statement removed all " ", "\n", "\r", "\t" and "\f" characters THERE IS NOTHING FOR s/ //g TO REMOVE! > } This if block can be written more efficiently as: if ( /Sender:\s+(\S+)/ ) { ( $sender = $1 ) =~ tr/+//d; } > if (/^GET/) { # ohjausdataa ... > &getlogo($sender,$_); > $remove=1; > } > } > close FILE; > if ($remove == 1) { > `mv $file $handled`; > #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"; ^^^^^^ $gnokii > # Tutki which Operator > if ($sender =~ /^050/) { > system "gnokii --sendlogo op $sender $logo 244-05"; ^^^^^^ $gnokii > > } > elsif ($sender =~ /^040/) { > system "gnokii --sendlogo op $sender $logo 244-91"; ^^^^^^ $gnokii > } > } John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]