Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I want to be able to automatically test all of my servers to make sure that directory browsing is enabled. How do I do this in a shell script?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Two suggestions:

  • Create a directory, fetch its contents over HTTP from localhost (using curl, wget -O /dev/stdout, lynx -dump, w3m -dump, elinks -dump) and look for the file list. Example for Apache2, which normally shows Index of /directory:

    cd /srv/http
    name="test-$RANDOM$RANDOM$RANDOM"
    mkdir "$name"
    if curl "http://localhost/$name/" | fgrep -qs "Index of /$name"; then
        echo "enabled"
        rmdir "$name"
    else
        echo "disabled"
        rmdir "$name"
        exit 1
    fi
    

    If you are using Lighttpd, nginx or something else, adjust the grep pattern.

  • Alternative: Learn some grep or perl and parse the hell out of your configuration files. The exact process depends on the HTTP daemon you are using – their configuration formats are very different.

share|improve this answer
1  
Nice thanks! Also using curl to get the http response code works for me. 403 means directory listing is disabled, and 200 means it's enabled –  David Jun 22 '11 at 8:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.