Solved

Question for rj2

Posted on 2002-04-14
5
184 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
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Suggested Solutions

Title # Comments Views Activity
remove duplicates from the csv file 13 115
Port 80 requests 16 100
instmodsh - listing perl modules 2 83
Migrate OTRS to newest version. 1 374
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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…

856 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