Help with redirecting output to an HTML file

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Help with redirecting output to an HTML file
# 1  
Old 07-16-2015
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.

2. Relevant commands, code, scripts, algorithms:
This is my sysinfo_page script

Code:
#!/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)


3. The attempts at a solution (include all code and scripts):

I have tried to redirect the output by using this code

Code:
sysinfo_page < sysinfo_page.html

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

Code:
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!

4. 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
# 2  
Old 07-16-2015
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")
# 3  
Old 07-17-2015
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?

Last edited by braing; 07-17-2015 at 10:35 AM..
# 4  
Old 07-17-2015
What happens if you uncomment the
Code:
# write_page > $filename

line in your script? Make sure the space in front of _EOF_ is removed.
# 5  
Old 07-17-2015
That seems to have solved the majority of my problem.

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

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

Thank you for your help.
# 6  
Old 07-17-2015
How do you "run the html file"?
# 7  
Old 07-17-2015
Typing:
Code:
sysinfo_page.html

into the command line
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Redirecting output to file

Hi, I have created script which redirect the output to file.I am able to get the output in file but not in the format. Output :Content of the log which have 10 -15 lines. Actal :Line1 ..Line 2Line3 Line4 Line 5 Expected:Line1 Line 2 Line3 Please... (7 Replies)
Discussion started by: karthik771
7 Replies

2. UNIX for Dummies Questions & Answers

Help with redirecting output to an HTML file

I'm very new to shell scripting and am practicing how to write a script, then redirect the output into an HTML file, and then email both the script and the HTML file to myself. I have created a script called sysinfo_page, and thought it would have redirected the output into the sysinfo_page.html... (3 Replies)
Discussion started by: braing
3 Replies

3. Shell Programming and Scripting

Redirecting output to file through cron

Hi Does anyone have any suggestions for capturing the output into a file when i run it through cron? I have file called "quick.1" which contains two simple commands to be executed on the target host. And i have second file called "quick.2" which contains the wrapper script to ssh to the target... (1 Reply)
Discussion started by: chandika_diran
1 Replies

4. UNIX for Dummies Questions & Answers

redirecting the script output to more than 1 file

Hi, I want to redirect my script output to more than one file without printing the result to the screen. How to do that? ex: echo "hi" >> a.txt b.txt cat a.txt hi b.txt :confused: (2 Replies)
Discussion started by: boopathyvasagam
2 Replies

5. Shell Programming and Scripting

Redirecting output to file

Hi, Below is the whole string which is to be redirected to the new file. su - oracle -c "exp $user/$pass file=/oracle/oradata/backup/exp_trn_tables_`date +%d_%b_20%y_%H_%M_%S`.dmp log=/oracle/oradata/backup/exp_trn_tables_`date +%d_%b_20%y_%H_%M_%S`.log tables=table1,table2 statistics=none" ... (3 Replies)
Discussion started by: milink
3 Replies

6. Shell Programming and Scripting

Redirecting output of Make to file

Hi, I am unable to get this script to work as desired. Basically, if an argument "log" is sent into the script, it outputs the result of the Make to a file output.log. However, if the argument is not passed, I want the output to be just put on screen (no redirection). See code snippet below. #... (3 Replies)
Discussion started by: srujan45
3 Replies

7. Shell Programming and Scripting

Redirecting output of a command to a file

Hi We are having a requirement where one shell script, say a.sh (which uses Java and connects to Oracle database using JDBC) keeps on running everytime. I created a wrapper (to check whether a.sh is running and if not then to start it) and scheduled it in the crontab. Now all the output from... (3 Replies)
Discussion started by: ankitgoel
3 Replies

8. AIX

Redirecting Both to a file and std output

Hello Friends, Can some one help me how to redirect output of a file to both a file and std output? All the help would be greatly appreciated. Regards Sridhar (1 Reply)
Discussion started by: send2sridhar
1 Replies

9. Shell Programming and Scripting

Redirecting <talk> output to a file

Is it possible to run <talk> such that both sides of the conversation are written to the screen and also to a file? I use the utility to chat with collaborators and sometimes it would be nice to have a record of our conversation while we are problem solving. I am running OS X, so <talk>... (4 Replies)
Discussion started by: cej
4 Replies

10. Shell Programming and Scripting

Redirecting my output to a specific file

Hi guys am doing some checking inside my script and i want to redirect my output to a specific file for example checking if a move was successfully done and was writing on the screen whether the move was successful or not and now want to write same thing into a file... I am new to shell... (2 Replies)
Discussion started by: Lutchumaya
2 Replies
Login or Register to Ask a Question