Solved

Question for rj2

Posted on 2002-04-14
5
183 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Remove Malware code from PHP file 6 84
Any syntax error for this clone.plscript 6 139
PERL variable conundrum 9 91
Excel to CSV conversion with specific columns 5 82
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…
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 …
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

809 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