Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 189
  • Last Modified:

Question for rj2

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
arvind
Asked:
arvind
  • 3
  • 2
1 Solution
 
rj2Commented:
#!/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
 
arvindAuthor Commented:
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
 
arvindAuthor Commented:
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
 
rj2Commented:
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
 
rj2Commented:
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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now