Find the answer to your Linux question:
Page 1 of 3 1 2 3 LastLast
Results 1 to 10 of 24
www.geocities.com/mshah2k/m.html First, I set out to prove him wrong and thought that I could do it myself, but I was wrong . So I am posting here in hopes that ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Oct 2002
    Posts
    15

    Unix QUestion, help please


    www.geocities.com/mshah2k/m.html

    First, I set out to prove him wrong and thought that I could do it myself, but I was wrong . So I am posting here in hopes that someone will help me because now I am running out of time LOL. We havent done much scripting at all in class, so I am stuck. Here is what I have so far:


    I would do something like
    'ls -R -l'
    to get all recursive listing of directories and then process that somehow??

    And then I could do something like:

    arg=$1
    cmd="find . -name \""$arg"\"
    shift 1
    for i
    do
    cmd="$cmd -o -name \"$i\""
    done

    That'll get you a command that finds everything with any of the names you specified. Then just do

    $cmd | sort | while read i
    do
    echo "<A HREF=\"$i\">$i</A>"
    done


    Or something, I dont know, a lot of this is just winging it on my part, it doesnt compile anyway, so it may be off by a LONGSHOT. I would appreciate any and all help with this subject.

  2. #2
    Linux User
    Join Date
    Jul 2002
    Location
    Daytona Beach, FL
    Posts
    487
    what kind on assignment is this that it is being posted on a geocrap webpage?
    majorwoo

    Quiet brain, or I\'ll stab you with a Q-tip.

  3. #3
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    Well, I can't really say that the teacher seemed all too experienced, with capitalized file names, ugly tags and I don't know all. But it doesn't matter, it wasn't him I was supposed to help out, right? But please tell him that I said so. It's the kind of things that teachers need to here from time to time. =)
    It didn't say whether subdirectories should be indexed if not specified, I'm going with that they should only be indexed if specified, since he used "GenerateIndex *.pdf", which, of course, won't work very well for subdirectories. Here's a simple version:
    Code:
    #/bin/sh
    
    indexdir &#40;&#41;
    &#123;
        if &#91; -e "$indexname" &#93;; then
            return 0;
        fi
        rm "$indexname"    #To get the create perms from the umask
        cat >"$indexname" <<-EOF
            <html>
            <head><title>Index for `pwd`</title></head>
            <body>
    EOF
        while &#91;  $# -gt 0 &#93;; do
            for file in $1; do
                if &#91; -f $file &#93;; then
                    echo "<a href=\"$file\">$file</a>" >>"$indexname"
                fi
                if &#91; -d $file &#93;; then
                    &#40;cd "$file"; indexdir "*"&#41;
                fi
            done
            shift
        done
        cat >>"$indexname" <<-EOF
            </body>
            </html>
    EOF
    &#125;
    
    $indexname="$1"
    shift
    if &#91; $# -eq 0 &#93;; then
        indexdir "*"
    else
        indexdir "$@"
    fi
    That's without the commenting code. I can do that, too, if you really want me to.
    I take no responsibility for all the typos in there. I just wrote it down, so there's bound to be at least a couple of wrongs.

  4. #4
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    OK, I found the first ones. Firstly, I happened to write $indexname="$1", as you can see. Remove the dollar sign. Also, to avoid a stupid warning, use rm -f "$indexname instead of just rm "$indexname". It also doesn't do any error checking if the index file name isn't given. But maybe that not such a big problem.

  5. #5
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    Also, a thing worth mentioning. It's not a big deal, but if you don't want the html files to look weirder than they must, be sure to indent with tabs, not spaces, in the here-documents to cat.

  6. #6
    Linux Engineer
    Join Date
    Jan 2003
    Location
    Lebanon, pa
    Posts
    994
    To bad you can't use perl for that

  7. #7
    Just Joined!
    Join Date
    Oct 2002
    Posts
    15
    ALL subdirectories within the folders should be indexed. I dont think you have to specify what directories should be indexed and what shouldnt.
    If the user types this:

    GenerateIndex index.html *.ps *.pdf *.txt

    Then it should look at ALL directories and subdirectories and sub-subdirectories...etc..and create an index file in EACH of them. THere is no option for specifying which directories to index, you must do all of them.

    what kind on assignment is this that it is being posted on a geocrap webpage?

    Actually its posted on a class web site but you need a username/password to access it, so I had to put it on a geocities website. I havent had any problems with geocities, do you recommend something better.

    Well, I can't really say that the teacher seemed all too experienced, with capitalized file names, ugly tags and I don't know all. But it doesn't matter, it wasn't him I was supposed to help out, right? But please tell him that I said so. It's the kind of things that teachers need to here from time to time. =)

    To tell ya the truth, I am not sure he has ever been out of Academia, but he seems nice enough and I dont want to get on his bad side LOL.

  8. #8
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    You know, if you run GenerateIndex index.html *.ps *.pdf *.txt, the shell will only pass the names of all matching files in the cwd, not the wildcards themselves. For example, say you have the following files in your cwd:

    file1.ps
    file2.pdf
    file3.txt

    Then you run the command exactly as shown there, the actual command that is run by the shell is GenerateIndex index.html file1.ps file2.pdf file3.txt, not GenerateIndex index.html *.ps *.pdf *.txt. That means that those files are pretty unlikely to be found in any subdirectories, except accidentally.
    That is why I thought that directories should only be indexed if their names are given on the cmdline or match any quoted wildcard given on the cmdline. Are you sure that is not the case?

  9. #9
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    Some side notes:

    Quote Originally Posted by mshah2k
    I havent had any problems with geocities, do you recommend something better.
    Run your own HTTP server? It's really not that hard, unless you're on dial-up.

    Quote Originally Posted by genlee
    To bad you can't use perl for that
    How comes I was almost suspecting that comment? =)

    Quote Originally Posted by majorwoo
    what kind on assignment is this that it is being posted on a geocrap webpage?
    If you would have looked at the address, you would have seen his user name there... I don't know if I am the one who should pick on things such as overlooking details, though... =)

  10. #10
    Just Joined!
    Join Date
    Oct 2002
    Posts
    15
    No, all directories need to be indexed. Hmm I wasnt aware that the shell would do only this. I will ask my intructor tomorrow about it and report back .

Page 1 of 3 1 2 3 LastLast

Posting Permissions

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