Debugging a beginner shell script...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Debugging a beginner shell script...
# 1  
Old 02-02-2010
Debugging a beginner shell script...

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

========================================================

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

===================================================

Last edited by pludi; 02-03-2010 at 02:26 AM.. Reason: code tags, please..
# 2  
Old 02-02-2010
You need to use appropriate spacing inside the test brackets. Try:
Code:
if [ "$response" != "y" ]; then

# 3  
Old 02-03-2010
Quote:
Originally Posted by brokepunk
i am stuck with a command not found issue when asking for a y/n response from the user.

When you get an error message, read it!.

The message would tell you which command was not found. Is what it tells you an actual command or is it a typo?
# 4  
Old 02-03-2010
Thank you...

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

++++++++++++++++++++++++++++++++++++++++++++++++++++++=

All help will be greatly appreciated.
# 5  
Old 02-03-2010
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.
# 6  
Old 02-03-2010
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...

Writing shell scripts - Lesson 13: Positional Parameters

Above is a link to the tutorial I am following... I am a little farther along then this page, but this is where things start to fall apart.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script debugging

hi all only the weirdest thing happened with me just now. I was debugging a shell script and I found that a step that was supposed to execute later was getting executed prior to another step for no reason. You know any ? i mean have a look at the following command- here it tries to grep... (7 Replies)
Discussion started by: leghorn
7 Replies

2. Homework & Coursework Questions

Shell Script (beginner)

1. The problem statement, all variables and given/known data: Arguments: http://farm9.staticflickr.com/8070/8212131370_8b6e8c10c5_c.jpg I am given these three arguments. $1, $2, $3 The first argument is the path to a directory. So, how would I go into the directory and compare files? I... (5 Replies)
Discussion started by: spider-man
5 Replies

3. Homework & Coursework Questions

Shell-script loops beginner

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: "Create a shell script that changes the selected word to another word in all files from selected archive. The... (1 Reply)
Discussion started by: oibanuelos
1 Replies

4. Shell Programming and Scripting

Shell script (beginner) need help...

Hello, I'm new to Sheel script and I need your help for a script I need to develop (for me). Indead, I have a software which log all entry from internet and save it in text file. But, the log is practically unreadable because every 256 characters jump to a new line (even if the message is... (5 Replies)
Discussion started by: acidoangel
5 Replies

5. Shell Programming and Scripting

Beginner shell script help

. ./testFile.sh url=http://ichart.finance.yahoo.com/table.csv?s= suf=&d=5&e=9&f=2009&g=d&a=1&b=4&c=1999&ignore=.csv wget $url$s1$suf; sleep 10; cat header.txt > $s1.txt; chmod 777 $s1.txt; sed '1d' table.csv?s\=$s1 >> $s1.txt; rm -Rf table* Very new at shell scripting as you can see... (3 Replies)
Discussion started by: harte
3 Replies

6. Shell Programming and Scripting

debugging the shell script with out actually running

Hello, Some one asked me in the inteview.... The question is, How do we debug the schell script before even running..... Interviewer told me one clue... There is SET command to accomplish this... Can any one tell me what kind of set commands.... Thanks. (2 Replies)
Discussion started by: govindts
2 Replies

7. UNIX for Advanced & Expert Users

which one method is best for debugging the shell script?

Hi All, How to debug the unix shell script? which one is the best way to do the debuging ? suggession would be appreciate Regards, Siva P Bangalore (2 Replies)
Discussion started by: psiva_arul
2 Replies

8. Shell Programming and Scripting

HP-UX Debugging Shell script

Hi, I was using AIX - ksh shell , and inorder to debug shell script I used set -vx to echo all the commands which are being executed. Can anybody tell me the corresponding method in HP-UX - in tcsh shell. Regards Shihab (1 Reply)
Discussion started by: shihabvk
1 Replies

9. Shell Programming and Scripting

Shell Script for Beginner

I have a folder with lots of file. e.g. a.txt, b.txt, c.txt.... I want to put these files from the source directory and place them in a destination directory in a specific order, such as /destination/a/a.txt, /destination/b/b.txt, /destination/c/c.txt, ...... Please help. Thx :confused: (3 Replies)
Discussion started by: aaron_fong
3 Replies

10. Shell Programming and Scripting

Beginner trying to write a shell script!

Dear All, I'm trying to write a shell script that continously checks a certain folder. When a file is placed in the directory securely copies the file to another server. I've got the secure copying working, but I don't know how to contiously check a directory for a new file and then use that... (3 Replies)
Discussion started by: duncan_glover
3 Replies
Login or Register to Ask a Question