Help with redirecting output to an HTML file

  1. The problem statement, all variables and given/known data:
    I'm having trouble redirecting the output of my sysinfo_page script into my sysinfo_page.html file. The task at hand is to be able to email both the html file and the script to myself. I'm assuming that the html should appear as a web page when I email it to myself, but only one line of the sysinfo_page script is appearing in the html file.

The shell script file is named sysinfo_page and the html file is named sysinfo_page.html.
Both files are executable by the user.
They are both located in the bin directory.

  1. Relevant commands, code, scripts, algorithms:
    This is my sysinfo_page script
#!/bin/bash -x

#sysinfo_page - A script to produce a system information HTML file

##### Constants

TITLE="System Information for $HOSTNAME"
RIGHT_NOW=$(date +"%x %r %Z")
TIME_STAMP="Updated on $RIGHT_NOW by $USER"

##### Functions

system_info()
{
        # Find any release files in /etc

        if ls /etc/*release 1>/dev/null 2>&1; then
                echo "<h2>System release info</h2>"
                echo "<pre>"
                for i in /etc/*release; do

                        # Since we can't be sure of the
                        # length of the file, only
                        # display the first line.

                        head -n 1 $i
                done
                uname -orp
                echo "</pre>"
        fi

}       # end of system_info

show_uptime()
{
        echo "<h2>System uptime</h2>"
        echo "<pre>"
        uptime
        echo "</pre>"

}       # end of show_uptime

drive_space()
{
        echo "<h2>Filesystem space</h2>"
        echo "<pre>"
        df
        echo "</pre>"

}       # end of drive_space

home_space()
{
        # Only the superuser can get this information

        if [ "$(id -u)" = "0" ]; then
                echo "<h2>Home directory space by user</h2>"
                echo "<pre>"
                echo "Bytes Directory"
                du -s /home/* | sort -nr
                echo "</pre>"
        fi

}       # end of home_space

write_page()
{
        cat <<- _EOF_
        <html>
                <head>
                <title>$TITLE</title>
                </head>
                <body>
                <h1>$TITLE</h1>
                <p>$TIME_STAMP</p>
                $(system_info)
                $(show_uptime)
                $(drive_space)
                $(home_space)
                </body>
        </html>
_EOF_

}

usage()
{
        echo "usage: sysinfo_page [[[-f file ] [-i]] | [-h]]"
}

##### Main

interactive=
filename=~/sysinfo_page.html

while [ "$1" != "" ]; do
        case $1 in
  -f | --file )           shift
                                        filename=$1
                                        ;;
                -i | --interactive )    interactive=1
                                        ;;
                -h | --help )           usage
                                        exit
                                        ;;
                * )                     usage
                                        exit 1
        esac
        shift
done

# Test code to verify command line processing

if [ "$interactive" = "1" ]; then

        response=

        echo -n  "Enter name of output file [$filename] > "
        read response
        if [ -n "$response" ]; then
                filename=$response
        fi

        if [ -f $filename ]; then
        echo -n "Output file exists. Overwrite? (y/n) > "
                read response
                if [ "$response" != "y" ]; then
                        echo "Exiting program."
                        exit 1
                fi
 fi
fi

# Write page (comment out until testing is complete)

# write_page > $filename
(END)
  1. The attempts at a solution (include all code and scripts):

I have tried to redirect the output by using this code

sysinfo_page < sysinfo_page.html

When I did that, only this line appeared in the sysinfo_page.html file

Enter name of output file [/home/b-ingram3/sysinfo_page.html] >

I assume the problem must be that I'm missing something within the script but I can't quite catch what that may me. Thanks for any suggestions!

  1. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
    Hudson Valley CC, Troy NY, USA, Prof. Looby, CISS 100

Assuming that you redirected stdout and NOT stdin (as posted above), with the script as posted I regard it logical that the html file contains just that one line, as it's the only output to stdout.
If uncommenting the write_page call, make sure the here document's syntax is correct (no space in front of the "word")

Thanks for your reply. Yes, I did redirect stdout. I mistakenly wrote the code wrong on this post. Do you have any suggestions on anything I could move around or add in order for the entire script to be redirected into the html file as a web page?

What happens if you uncomment the

# write_page > $filename 

line in your script? Make sure the space in front of _EOF_ is removed.

That seems to have solved the majority of my problem.

Though when I run the html file, I receive this code.

line 1: syntax error near unexpected token. `newline' 

Thank you for your help.

How do you "run the html file"?

Typing:

sysinfo_page.html

into the command line

You know that html files are to be interpreted by some type of browser?

Suggestion. Run the script using bash -x <script>
Review the output and/or post here.