Results 1 to 8 of 8
  1. #1
    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?

  2. #2
    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.

  3. #3
    Join Date
    Feb 2005
    Location
    Australia
    Posts
    5,849
    Quote Originally Posted by Kadence View Post
    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?
    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
    Then test for existence of that file in .htaccess, and redirect to your cgi program if not:
    Code:
    RewriteCond /path/to/logdir/%{REQUEST_URI}/%{REMOTE_ADDR} !-f
    RewriteRule (.*) script.cgi [L]
    Then your cgi script would need to touch the request_uri/ip filename (as above) to create the file and then either serve the page requested or send a redirect to load the same page again.

    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

  4. #4
    Join Date
    Mar 2008
    Location
    kolkata, India
    Posts
    102
    Permission can play a role here?
    Sysfirm
    So you think your server is secure?
    Try our security Service
    With SysFirm

  5. #5
    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.

  6. #6
    Join Date
    Nov 2004
    Location
    New Jersey
    Posts
    113
    Quote Originally Posted by Tim Greer View Post
    You can use RewriteMap, such as:

    RewriteMap valuehere prg:/path/to/some-script.pl
    Thanks, I'll look into RewriteMap.
    Quote Originally Posted by applicurearun View Post
    Permission can play a role here?
    I have root permissions.
    Quote Originally Posted by tix3 View Post
    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.
    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?

  7. #7
    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.

  8. #8
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •