Solved

Question for rj2

Posted on 2002-04-14
5
185 Views
Last Modified: 2010-03-05
Hi Rj2 ,

Regarding http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=perl&qid=20275299

previos script. I would some addition for log facility.

Every submission through perl script will generate log - log details

recipient address - senderaddress - result(which is actuly MMID generate by URL) - logtimesent.

0
Comment
Question by:arvind
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 10

Expert Comment

by:rj2
ID: 6940330
#!/usr/bin/perl

use strict;

use Mail::Internet;
use LWP::Simple;
use Getopt::Std;
use URI::Escape;

my $message = new Mail::Internet \*STDIN;

my $subject = $message->head->get("Subject");
my $from = $message->head->get("From");
my $body=$message->body();
my ($number,$sender);

($number,$sender)=split(/\|/,$subject,2);

my $result=sendsms($number,join('',@$body),$sender);
logresults($number,$sender,$from,$result,scalar(localtime));

sub sendsms {
  my $number=shift;
  my $message=shift;
  my $sender=shift;
 
  #-i partner id
  #-a partner_an
  #-g partner_gateway
  my %args;
           
  getopt("iag",\%args);
 
       
  my $url=" http://partnerweb.some.com/Partner/api41/ChkDevSndMsg41.asp?partner_id=$args{i}&partner_an=$args{a}&partner_ap=predifined&partner_phone=$number&partner_gateway=$args{g}&from=predifined&fromaddr=$sender&msginv=$message";

  $url=uri_escape($url);

  #print "url=$url\n";

  #my $result=get($url);
  return('testresultat');

  print "$result\n";

  return($result);
}


sub logresults {
     my($s)=join("\t",@_);
     $s =~ s/\n//g;
     open(LOGFILE,'>>/home/arvind/send.log');
     print LOGFILE "$s\n";
     close(LOGFILE);
}
0
 
LVL 5

Author Comment

by:arvind
ID: 6941110
one more thing I would like in log- After calling submission url - If url submit successfully it gives a 6-7 digit number of ref..If I use ur script in command prompt I'm geting code - So I also want that code loged as MMID in log file.
0
 
LVL 5

Author Comment

by:arvind
ID: 6941233
Here are updated script:
-----------------------------------------
#!/usr/bin/perl

use strict;

use Mail::Internet;
use LWP::Simple;
use Getopt::Std;
use URI::Escape;

my $message = new Mail::Internet \*STDIN;

my $subject = $message->head->get("Subject");
my $from = $message->head->get("From");
my $body=$message->body();
my ($number,$sender);

($number,$sender)=split(/\|/,$subject,2);

my $result=sendsms($number,join('',@$body),$sender);
logresults($result,$number,$sender,$from,$result,scalar(localtime));

sub sendsms {
 my $number=shift;
 my $message=shift;
 my $sender=shift;
#-i partner id
#-a partner_an
#-g partner_gateway
 my %args;
 getopt("iag",\%args);
 
     
my $url="http://partnerweb.some.com/partner/api41/ChkDevSndMsg41.asp?partner_id=predefined&partner_an=predefined&partner_ap=predefined&partner_phone=$number&partner_gateway=1&from=linnetops&fromaddr=$sender&msginv=$message";

# $url=uri_escape($url);

print "url=$url\n";
my $result=get($url);
#return('testresultat');
#print "$result\n";

return($result);
}

sub logresults {
    my($s)=join("\t",@_);
    $s =~ s/\n//g;
    open(LOGFILE,'>>/var/log/sendsms.log');
    print LOGFILE "$s\n";
    close(LOGFILE);
}

------------------------------
here are the logs:

2086801 919845194696    9999999999999999        arvind@linnetops.corp.some.
com     2086801 Mon Apr 15 11:38:44 2002


So MMID(2086801 - I think it is result) printing two times. I would like proper format becoz second time log start without space. we can use single space as delimeter.

thnx in advance
Arvind
0
 
LVL 10

Expert Comment

by:rj2
ID: 6945790
Hello again!
I'm not sure I understand what you mean here.
Please post log samples both as it is now and how you would like it to be.
0
 
LVL 10

Accepted Solution

by:
rj2 earned 100 total points
ID: 6955757
replace
logresults($result,$number,$sender,$from,$result,scalar(localtime));

with
logresults($result,$number,$sender,$from,scalar(localtime));

should fix that result comes twice.

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question