Linux Script create index.html file | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Linux Script create index.html file

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 09-25-2010
seashell11 seashell11 is offline
Registered User
 
Join Date: Sep 2010
Last Activity: 25 September 2010, 12:48 PM EDT
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Linux Script create index.html file

I need a script that can do this:
  • A script that searches all directories and subdirectories for .html files
  • When a .html file is found it creates a index.html file in that folder.
  • It then edits the index.html file and inserts links to all of the .html files that are in that folder into the body.
  • If no .html files are found, it searches for folders.
  • It then creates a index.html file with links to all of the folders.

What would be the best way to do this? Do you need more information?

Thank You
Sponsored Links
    #2  
Old 09-25-2010
adelsin adelsin is offline
Registered User
 
Join Date: Feb 2010
Last Activity: 20 May 2011, 2:45 PM EDT
Posts: 123
Thanks: 2
Thanked 1 Time in 1 Post
Are we doing your homework? How far have you gotten?
Sponsored Links
    #3  
Old 09-25-2010
seashell11 seashell11 is offline
Registered User
 
Join Date: Sep 2010
Last Activity: 25 September 2010, 12:48 PM EDT
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
I haven't did much with scripts before. I am still researching best ways to do it.

Here is how I was thinking I will do it, but I haven't got the script written yet:

Use the `find` command to locate every directory within the parent tree, including the top directory. Then, inside every one of the found directories, I will use `find` again (with a -maxdepth of 1) to locate all directories & html files present; then I'll create the index.html file, and insert (probably just using `echo`) a <href=link> to each directory and/or html file present within my current directory.
    #4  
Old 09-25-2010
adelsin adelsin is offline
Registered User
 
Join Date: Feb 2010
Last Activity: 20 May 2011, 2:45 PM EDT
Posts: 123
Thanks: 2
Thanked 1 Time in 1 Post
I'll get you started a bit.


Code:
 find / | grep *.html

You'll have to do a foreach on the above to get this part. For the actual writing of the file


Code:
 echo "<a href\=$_>$_<\/a>"  >> destination.html"

I don't want to give you all the answers. Just trying to help out with syntaxes.
Sponsored Links
    #5  
Old 09-25-2010
seashell11 seashell11 is offline
Registered User
 
Join Date: Sep 2010
Last Activity: 25 September 2010, 12:48 PM EDT
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Thank You. And no, this is not for homework. It is for a personal web server that I set up so that I can watch all of my movies in WebM format with my laptop. I already wrote a script that finds all of the WebM files and creates a html file for each webm file so that I can view them. Now I just am figuring out how to make indexes of all of the files.
Sponsored Links
    #6  
Old 09-25-2010
rdcwayx rdcwayx is offline Forum Advisor  
Use nawk in Solaris
 
Join Date: Jun 2006
Last Activity: 22 March 2014, 12:27 PM EDT
Posts: 2,759
Thanks: 44
Thanked 418 Times in 406 Posts
Some hints for you.

A script that searches all directories and subdirectories for .html files


Code:
find /ALL_DIRECTORIES -name "*.html" -type f -print

When a .html file is found it creates a index.html file in that folder.

Code:
find /ALL_DIRECTORIES -name "*.html" -type f -exec dirname {} \; |sort -u |while read dir
do
  if [ -f "$dir"/index.html ] 
  then
     touch "$dir"/index.html
  fi
done

for rest, you need tell us what type of links you need write in the index.html files for these .html files and folders.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
help with a bash script to create a html table dunryc Shell Programming and Scripting 2 03-06-2010 09:35 PM
Create a html file if a process is running?? Hangman2 Shell Programming and Scripting 1 05-13-2009 12:36 PM
why the inode index of file system starts from 1 unlike array index(0) sairamdevotee Filesystems, Disks and Memory 0 08-17-2008 04:50 AM
New SEO Experiment http://www.globalfactbook.com/index.html Neo Web Programming 1 07-14-2008 12:03 PM
which access right should set in my webpage index.html ? zp523444 UNIX for Advanced & Expert Users 1 11-13-2005 02:27 AM



All times are GMT -4. The time now is 07:42 AM.