Solved

Question for rj2

Posted on 2002-04-14
5
182 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
  • 3
  • 2
5 Comments
 
LVL 10

Expert Comment

by:rj2
Comment Utility
#!/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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now