I've been trying to get this function to work without returning errors, but so far I'm unable to figure out what the problems is. I'm using $(report_home_space) to insert the contents of the functions on a small bit of hmtl but keep getting the error: report_home_space: command not found on line 30.
report_home_space () {
cat <<- _EOF_
<H2>Home Space Utilization</H2>
<PRE>$(du -sh /home/*)</PRE>
_EOF_
}
I'm new to shell scripting, but I can't not find anything wrong with the syntax of the function, and the spelling seems correct. Thanks in advance.
Full script is:
#!/bin/bash
# Program to output a system information page
TITLE="System Information Report For $HOSTNAME"
CURRENT_TIME=$(date +"%x %r %z")
TIMESTAMP="Generated $CURRENT_TIME, by $USER"
report_uptime () {
cat <<- _EOF_
<H2>system Uptime</H2>
<PRE>$(uptime)</PRE>
_EOF_
}
report_disk_space () {
cat <<- _EOF_
<H2>Disk Space Ulitilizatoin</H2>
<PRE>$(df -h)</PRE>
_EOF_
}
report_home_space () {
cat <<- _EOF_
<H2>Home Space Utilization</H2>
<PRE>$(du -sh /home/*)</PRE>
_EOF_
}
cat << _EOF_
<HTML>
<HEAD>
<TITLE>$TITLE</TITLE>
<BODY>
<H1>$TITLE</H1>
<P>$TIMESTAMP</P>
$(report_uptime)
$(report_disk_space)
$(report_home_space)
</BODY>
<HTML>
_EOF_

<<-is risky, as it's easy for tabs to be converted to spaces during copy/paste; safer to use<<and not indent the closing delimiter, ugly as that is.catinvocations (which all involve afork()/exec()cycle, after all). Consider usingprintf '%s\n' "<H2>System Uptime</H2>" "<PRE>$(uptime)</PRE>"or the like.printfrecommendation but you beat me to it. :)printfover what I'm currently using. Thanks.