Results 1 to 8 of 8
-
03-24-2008, 04:17 PM #1WHT Addict
- Join Date
- Nov 2004
- Location
- New Jersey
- Posts
- 113
Can .htaccess call a script (e.g. a bash .sh script)?
Is it possible to have .htaccess interact with a script, like a bash .sh script?
For instance calling the script to execute for every request, and/or passing information like the remote IP and request URI to the bash script?
-
03-24-2008, 05:56 PM #2Aspiring Evangelist
- Join Date
- Aug 2007
- Location
- Greece
- Posts
- 390
No,not to my knowledge.
If it is for your other topic problem you could write a shell script that greps the netstat in a while [1] and if you find the selected ip range then mail to you.NOT a webhost!helping here just for the fun of it!
G(r)eek inside.
-
03-24-2008, 07:30 PM #3Retired Moderator
- Join Date
- Feb 2005
- Location
- Australia
- Posts
- 5,849
I think it would be possible, technically, by a roundabout route. Whether it's advisable to do this is another matter altogether, but...
You could use files to log access to each uri by each ip, eg. with a file structure like this:
Code:logdir/request/uri/111.222.333.444
Code:RewriteCond /path/to/logdir/%{REQUEST_URI}/%{REMOTE_ADDR} !-f RewriteRule (.*) script.cgi [L]
All in all, I think you'd find tix3's suggestion easier.Chris
"Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them." - Laurence J. Peter
-
03-25-2008, 05:40 PM #4WHT Addict
- Join Date
- Mar 2008
- Location
- kolkata, India
- Posts
- 102
-
03-25-2008, 09:03 PM #5Web Hosting Master
- Join Date
- Apr 2000
- Location
- California
- Posts
- 3,051
Yes, you can, but it depends on how you mean. It doesn't have to redirect for a web request to a script. You can use RewriteMap, such as:
RewriteMap valuehere prg:/path/to/some-script.pl
Or even do something like:
RewriteRule ^value:(.+) /path/to/script.here?this=$1 [T=application/x-httpd-cgi,L]
What you want to do, how it'll work and the intent, all depend, so the answer could be yes or no, or "yes, but with some tweaking". With conditions and things like RewriteMap, you can even execute a script on another system, based upon whatever you want (even the time of day, right from rewrite stuff only).
This can get pretty complex, depending on your goal and there's probably better ways to do it, based upon the conditions and rules of the rewrite recipe you want or need.
-
03-26-2008, 01:47 AM #6WHT Addict
- Join Date
- Nov 2004
- Location
- New Jersey
- Posts
- 113
Thanks, I'll look into RewriteMap.
I have root permissions.
Sounds like a good suggestion.
Though unfortunately I don't really know how to write a script that continually greps the netstat Does anyone know what I'd have to do here? Is it complicated? And how would I get this to run continually in the background?
-
03-26-2008, 02:00 AM #7Web Hosting Master
- Join Date
- Apr 2000
- Location
- California
- Posts
- 3,051
netstat? What are you trying to accomplish exactly? There may be better methods here. For example, access logs have the IP, URI, "referer" and so on. What details are you looking to have and do they need to be in real time, or just to refer to them? In what way would they need to be in real time, if at all? I'm certain there is a better way to achieve your goal, provided you outline the details of what you need.
-
03-26-2008, 03:59 PM #8WHT Addict
- Join Date
- Nov 2004
- Location
- New Jersey
- Posts
- 113
It's not necessarily just one specific thing, there's a few ideas that I want to implement, such as checking to see if a certain IP or IP range ever accesses the server, or if a certain URI is accessed. And I'm sure I could think of some other stuff if such a thing as calling a bash script via .htaccess was possible (various custom traffic stats, etc.).
I figured the best way to do the IP/URI checking would be to call some bash script via .htaccess or httpd.conf, if possible. Though perhaps grepping netstat as recommended above would be better. I could also grep server log files as someone else recommended, but that's pretty slow, and also ideally I'd like a solution that can work server-wide rather than have to check each different log separately (there's also the problem of new accounts having new log files).
Thanks for the responses so far