Results 1 to 2 of 2
  1. #1
    Join Date
    May 2012
    Posts
    1

    Unanswered: Help with Bourne Shell Script

    Hi all
    I have a little problem with bourne shell. I've just started writing that kind of scripts
    I have to write a script that search in folder for header.txt, footer. and content.txt. If these files exists i have to copy the content from them (ignoring the lines with #) and generate HTML file with this data where the content from file footer.txt goes between footer tags, the text from header.txt in header tags and content between them. After that I have to check date of the files. If the tree files are newer than the HTML i have to generate a new one , if not to exit the script. In the three files (header.txt, footer. and content.txt) i can have all kind of text withoth head and body tags.
    The code i write so far is :

    Code:
    #!/bin/sh
    echo "Enter folder path: "
    read path
    cd
    cd $path
    file1="header.txt" 
    file2="footer.txt"
    file3="content.txt"
    file4="project.html" 
    if [ -e $file1 ]
      then echo "Header.txt exists"
      else echo "Header.txt doesn't exists"
    fi
    if [ -e $file2 ]
      then echo "Footer.txt exists"
      else echo "Footer.txt doesn't exists"
    fi
    if [ -e $file3 ]
      then echo "Content.txt exists"
      else echo "Content.txt doesn't exists"
    fi
    if [ -e $file4 ]
      then if (test $file4 -ot $file1 -a $file4 -ot $file2 -a $file4 -ot $file3)
               then   # create new HTML
               else exit()
             fi
      else 
       (cat <<-_EOF_
    <body>
    <header>
    cat >> $(file1) 
    </header>
    cat >> $($file2)
    <footer>
    cat >> $($file3)
    </footer>
    </body>
    _EOF_
    )> project.html
    echo "Project.html has been created"
    fi
    I havin problem with that part. I am checking if the html file exists, after that if it's true i have to compare the modify dates and if the html is older than the other three to create new one, if not to exit the program. If the html doesn't exist i have to create one. Can you help me that function please
    Code:
    if [ -e $file4 ]
      then if (test $file4 -ot $file1 -a $file4 -ot $file2 -a $file4 -ot $file3)
               then   # create new HTML
               else exit()
             fi
      else 
       (cat <<-_EOF_
    <body>
    <header>
    cat >> $(file1) 
    </header>
    cat >> $($file2)
    <footer>
    cat >> $($file3)
    </footer>
    </body>
    _EOF_
    )> project.html
    echo "Project.html has been created"
    fi
    thank you in advance

  2. #2
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,057
    Provided Answers: 1
    Code:
      else 
     
    echo "<body>\n<header>" >project.html
    cat  $(file1) >>project.html 
    echo "</header>" >>project.html
    cat  $($file2) >>project.html
    echo "<footer>" >>project.html
    cat  $($file3)  >>project.html
    echo "</footer>\n</body>" >>project.html
    echo "Project.html has been created"
    fi

Posting Permissions

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