I have been following a tutorial on bash which has proven to be very helpful. However, i am stuck with a command not found issue when asking for a y/n response from the user. Below is the part of code I believe is giving me grief... I have been trying to work through this for 3 hours now.... Please let me know if you see anything here or need a larger sample of code to review.
Thanks very much...
if [ "$interactive" = "1" ]; then
response=
echo -n "Enter name of output file [$filename] > "
read response
if [ -n "$response" ]; then
filename=$response
fi
set -x
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
set +x
You were correct Scrutinizer, it was the spacing. I did read the error message but could not make sense of it until the folly of my ways was made clear to me...
So that part of the script is now fully functional but I cannot get permissions on the .gvfs to be read from superuser. I have read that this is a fuse mount point, and therefor not located in /etc/fstab. so When I unmount it, chmod and try to mount again... it bombs out not knowing where to look. There are a few more chapters on the tutorial I am working on, but before I complete them, I would like o understand my current issue. My first post got me scolded by a mod for not using correct code tags, so I am going to try this again with the entire script.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#!/bin/bash
# systeminfo - A script to produce an HTML file with system info.
##### Constants
TITLE="System Information for $HOSTNAME"
RIGHT_NOW=$(date +"%x %r %Z")
TIME_STAMP="Updated on $RIGHT_NOW by $USER"
##### Functions
function press_enter
{
echo ""
echo -n "Press Enter to continue"
read
clear
}
function system_info
{
echo "<h2>System release info</h2>"
echo "<p>Function not yet implimented</p>"
} # end of system_info
function show_uptime
{
echo "<h2>System Uptime</h2>"
echo "<pre>"
uptime
echo "</pre>"
} # end of show_uptime
function drive_space
{
echo "<h2>Filesystem space</h2>"
echo "<pre>"
df
echo "</pre>"
} # end of drive_space
# this is the function that requires superuser. I changed the id to 1000 just to see results and it worked, but no dice with root.
function home_space
{
# Only 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
function write_page
{
cat <<- _EOF_
<html>
<head>
<center>
<title>$TITLE</title>
</center>
</head>
<body>
<center>
<h1>$TITLE</h1>
<p>$TIME_STAMP</p>
$(system_info)
$(show_uptime)
<table border="1">
<tr>
<td>
$(drive_space)
</td>
<td>
$(home_space)
</td>
</table>
</center>
</body>
</html>
_EOF_
}
function usage
{
echo "usage: systeminfo [[[-f file ] [-i]] | [-h]]"
}
press_enter
##### Main
interactive=
filename=~/system_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
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
write_page > $filename
If this is an online tutorial are you able to post a link to a topic which defines ".gvfs" .
Please also post what Operating System and hardware you have because questions about mountpoints are invariably specific to the Operating System and hardware.
This online tutorial had no mention of the .gvfs issue. I found that out by running the script, then spending the next few hours trying to find why my permissions were denied. The .gvfs is located in /home/username. Im still not 100% on what it does or how it works and will do more reading on it today. However I tried chmod 777 and chown root under su and it still gave me permission denied. HOW IS THAT EVEN POSSIBLE!!!
Currently running ubunto 9.10 karmic
x86 plenty o' ram and two dual core 2ghz procs.
The function causing the problem is "home_space"
When I changed id -u to 1000(my group((is that a group, you know where root is 0?)) ) I weas able to push some results to the html page produced, permission denied errors show in bash, but not in the results ( pleasent suprise ).
Thank you again, and I am new to these forums... I promise I will get more concise when I learn what information will best help other members help me...