LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-05-2011, 01:00 PM   #1
musendrophilus
LQ Newbie
 
Registered: Oct 2010
Posts: 12

Rep: Reputation: 0
Question Help with an old script


A friend of mine from a long time ago wrote a perl script for me. It used to notify me via email when people from certain chosen domains visit my personal website.
The script still works but only for a single domain (pcisys.net). It no longer works when someone from comcast.net, qwest.net, et al visit my site unless I set it to look for something specific.
Code:
#!/usr/bin/perl

# notify.pl

# Mail notification when a visitor from a domain comes to mouse's site.


$RCP= 'notif@website.org';

$SBJ = 'visitor notification';

@STALKED = ('comcast.net', 'qwest.net', 'pcisys.net');



print "Content-type: text/plain\r\n";

print "\r\n";



$stalked_RE = '(' . join('|', @STALKED) . ')$';

exit unless $ENV{REMOTE_HOST} =~ /$stalked_RE/;



open(PP, "|/usr/sbin/sendmail -t") or die;

print PP <<"EOF";

To: $RCP

Subject: $SBJ



Dear mouse,



Hit from $ENV{REMOTE_HOST} via $ENV{HTTP_REFERER}.



EOF

close(PP);
Now I did change one property by adding wildcards in the hopes that the script would work as intended once again.

Code:
@STALKED = ('*.comcast.net', '*.qwest.net', 'pcisys.net');
But no dice.

Anyone have recommendations or suggestions? I know very little programming.
 
Old 01-05-2011, 03:17 PM   #2
harry edwards
Member
 
Registered: Nov 2007
Location: Lincolnshire, UK
Distribution: CentOS, Fedora, and Suse
Posts: 365

Rep: Reputation: 48
This test case works fine. Thus, your code looks fine.
Code:
#!/usr/bin/perl

$ENV{REMOTE_HOST}='pcisys.net';

@STALKED = ('comcast.net', 'qwest.net', 'pcisys.net');

$stalked_RE = '(' . join('|', @STALKED) . ')$';

print "Array content [" . $stalked_RE . "]\n";

exit unless $ENV{REMOTE_HOST} =~ /$stalked_RE/;

print "Match\n";
Add some print commands for debugging. Print the content of the $ENV variable and ensure it is what you expect.
 
Old 01-05-2011, 03:30 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Quote:
Originally Posted by musendrophilus View Post
A friend of mine from a long time ago wrote a perl script for me. It used to notify me via email when people from certain chosen domains visit my personal website.
The script still works but only for a single domain (pcisys.net). It no longer works when someone from comcast.net, qwest.net, et al visit my site unless I set it to look for something specific.
Code:
#!/usr/bin/perl

# notify.pl

# Mail notification when a visitor from a domain comes to mouse's site.


$RCP= 'notif@website.org';

$SBJ = 'visitor notification';

@STALKED = ('comcast.net', 'qwest.net', 'pcisys.net');



print "Content-type: text/plain\r\n";

print "\r\n";



$stalked_RE = '(' . join('|', @STALKED) . ')$';

exit unless $ENV{REMOTE_HOST} =~ /$stalked_RE/;



open(PP, "|/usr/sbin/sendmail -t") or die;

print PP <<"EOF";

To: $RCP

Subject: $SBJ



Dear mouse,



Hit from $ENV{REMOTE_HOST} via $ENV{HTTP_REFERER}.



EOF

close(PP);
Now I did change one property by adding wildcards in the hopes that the script would work as intended once again.

Code:
@STALKED = ('*.comcast.net', '*.qwest.net', 'pcisys.net');
But no dice.

Anyone have recommendations or suggestions? I know very little programming.

Since the wildcards are to become part of a RE they don't make sense
in the way you used them. Try:

Code:
@STALKED = ('.*\.comcast\.net', '.*\.qwest\.net', 'pcisys\.net');
instead ...



Cheers,
Tink
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash script problem with ftp session exiting the script early edomingox Programming 5 02-23-2010 05:39 AM
How to get full path to script file inside script itself? And in case of sym links? maggus Linux - Newbie 3 05-28-2009 08:40 AM
ssh - using variables in call to start remote script from local script babag Linux - Networking 2 06-03-2008 04:50 PM
set variables in a bash script; ansi PS1 color script donnied Programming 4 11-21-2007 11:33 AM
Shell Script: want to insert values in database when update script runs ring Programming 2 10-25-2007 10:48 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:47 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration