modify multiple .htaccess files at once?
Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: modify multiple .htaccess files at once?

  1. #1
    Priapistic Monk KorpDeath's Avatar
    Join Date
    Dec 2001
    Posts
    2,628

    modify multiple .htaccess files at once?

    Okay, I've got a problema folks. I have about 44 .htaccess files in 44 different directories that I need to change. Is there an easy way to modify all of these at the same time?

    I'm sure there's a cute script somebody has . . . maybe. . .

    Let me know, I'd rather not have to do this one at a time, and trust me it's not that I'm lazy it's just I've got fires burning all around me and I'd rather just be able to push a button and remove access for certain people. If you know what I mean....

    Thanks for any and all help in this matter.

    <edit> Obviously this is Linux and Apache I'm talking about.
    Mankind have a great aversion to intellectual labor; but even supposing knowledge to be easily attainable, more people would be content to be ignorant than would take even a little trouble to acquire it.
    - Samuel Johnson

  2. #2
    Hi mom!
    Join Date
    Aug 2001
    Posts
    1,103
    I'm hardly a bashscript wizz (so be sure to make backups of your original files!) but something like this might be useful:

    Code:
    #!/bin/bash
    while read line
    do
      echo ${line#$1}
    done
    exit 0
    If you save this to say removeStuff.sh and chmod 700 it, you'd use it like this:

    ./removeStuff.sh TOBEDELETED &lt; FILE

    You'd get a screendump of FILE with the first occurrence of TOBEDELETED removed from each line.

    Note that your original file is not overwritten and that this processes just one file, but if used in a(nother) script, it would at least save you some time.
    I wish to express my gratitude to the people of Italy. Thank you for inventing pizza.

  3. #3
    Senior Member
    Join Date
    Nov 2001
    Posts
    1,255
    Korp, no offense, but a general observation of all the recent questions you've asked about administering systems, I'd encourage you to learn Perl. A decent scripting language is a necessity for manageable administration, and you can do things like what you have asked about here in Perl in a very small script.

    Sorry if this seems off topic, but it can really save you a lot of time.
    Chris Shepherd
    The Nelson-Shepherd cutoff: The point at which you realise someone is an idiot while trying to help them.
    \"Well as far as the spelling, I speak fluently both your native languages. Do you even can try spell mine ?\" -- Failed Insult
    Is your whole family retarded, or did they just catch it from you?

  4. #4
    Priapistic Monk KorpDeath's Avatar
    Join Date
    Dec 2001
    Posts
    2,628
    None taken. I absolutely have every intention of learning not only Perl, but PHP and a few other things. If this wasn't an emergency I'd just take my time and read tons to get the "kungfu" myself but I don't have the luxury, ya know.

    Anyway, thanks for the suggestion. I know I may seem like a newb in some of these areas but I've never had this amount of exposure to *nix network administration.
    Mankind have a great aversion to intellectual labor; but even supposing knowledge to be easily attainable, more people would be content to be ignorant than would take even a little trouble to acquire it.
    - Samuel Johnson

  5. #5
    Hi mom!
    Join Date
    Aug 2001
    Posts
    1,103
    Hmm, while on that subject: what's the general feeling here about using PHP with the command line interface?

    I played around with it, and I find it quite useful (instead of #!/bin/bash you do #!/bin/php and be on your way).

    Is it useful to adopt CLI PHP as an substitution for Perl? In KorpDeaths case, the learning curve would be less steap: instead of two languages, he has to learn but one.
    I wish to express my gratitude to the people of Italy. Thank you for inventing pizza.

  6. #6
    Priapistic Monk KorpDeath's Avatar
    Join Date
    Dec 2001
    Posts
    2,628
    I'm all in favor of making things easier for myself...
    Mankind have a great aversion to intellectual labor; but even supposing knowledge to be easily attainable, more people would be content to be ignorant than would take even a little trouble to acquire it.
    - Samuel Johnson

  7. #7
    Banned
    Join Date
    Aug 2004
    Posts
    18
    Some elaboration on how you need the .htaccess files modified would certainly help.

  8. #8
    Leftie Linux Lover the_JinX's Avatar
    Join Date
    Nov 2001
    Location
    Beverwijk Netherlands
    Posts
    2,534
    If you'd like to add a line to all .htaccess files, there is a realy easy way..

    this can just be enterd in bash.. bash allows multiline stuff, so no script needed..
    it should add the word addition to all the .htaccess files

    Code:
    for htfile in `locate .htaccess`
    do
       echo "addition" &gt;&gt; "$htfile"
    done
    ASCII stupid question, get a stupid ANSI.
    When in Russia, pet a PETSCII.

    Get your ass over to SLAYRadio the best station for C64 Remixes !

  9. #9
    Hi mom!
    Join Date
    Aug 2001
    Posts
    1,103
    The problem is that you want to remove a name from a single line like this:

    Require user userid_a, userid_b, userid_c

    has to become:

    Require user userid_a, userid_c

    As far as I know, you can't get the same result by adding a line. You could construct something with Deny, but that directive doesn't take a userid in its syntax.

    More information in the Apache documentation at http://httpd.apache.org/docs-2.0/howto/auth.html
    I wish to express my gratitude to the people of Italy. Thank you for inventing pizza.

  10. #10
    Leftie Linux Lover the_JinX's Avatar
    Join Date
    Nov 2001
    Location
    Beverwijk Netherlands
    Posts
    2,534
    a replacement thing can be done in a simmilar way

    Code:
    for htfile in `locate .htaccess`
    do
       mv "$htfile" "$htfile.bak"
       cat "$htfile.bak" | sed -e "s/old/new/" &gt; "$htfile"
    done
    would for example change "old" into "new" ( and make a backup .htaccess.bak )

    <edit type="add">
    To do what Guus suggested you'd have to do a
    Code:
    sed -e "s/userid_b, //"
    </edit>
    ASCII stupid question, get a stupid ANSI.
    When in Russia, pet a PETSCII.

    Get your ass over to SLAYRadio the best station for C64 Remixes !

Posting Permissions

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