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.
- 01-28-2003 #1Just 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.
- 01-28-2003 #2Linux 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.
- 01-28-2003 #3Linux 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:
That's without the commenting code. I can do that, too, if you really want me to.Code:#/bin/sh indexdir () { if [ -e "$indexname" ]; 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 [ $# -gt 0 ]; do for file in $1; do if [ -f $file ]; then echo "<a href=\"$file\">$file</a>" >>"$indexname" fi if [ -d $file ]; then (cd "$file"; indexdir "*") fi done shift done cat >>"$indexname" <<-EOF </body> </html> EOF } $indexname="$1" shift if [ $# -eq 0 ]; then indexdir "*" else indexdir "$@" fi
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.
- 01-28-2003 #4Linux 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.
- 01-28-2003 #5Linux 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.
- 01-28-2003 #6Linux Engineer
- Join Date
- Jan 2003
- Location
- Lebanon, pa
- Posts
- 994
To bad you can't use perl for that
- 01-28-2003 #7Just 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.
- 01-28-2003 #8Linux 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?
- 01-28-2003 #9Linux Guru
- Join Date
- Oct 2001
- Location
- Täby, Sweden
- Posts
- 7,578
Some side notes:
Run your own HTTP server? It's really not that hard, unless you're on dial-up.
Originally Posted by mshah2k
How comes I was almost suspecting that comment? =)
Originally Posted by genlee
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... =)
Originally Posted by majorwoo
- 01-28-2003 #10Just 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
.


Reply With Quote
