- 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.
- 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)
- 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!
- 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