Error Message in function causing failure.....


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Error Message in function causing failure.....
# 1  
Old 08-23-2012
Error Message in function causing failure.....

I have a long busybox ash script that has 3 stages.

1. Identify and Capture information on variable data sources, output the information to text file on each data source.

2. Using data from 1 above now actually do data processing on each individual dataset.

3. Produce report.

So stage 1 detects what data sources are currently live, stage 2 then process's data on each source and stage 3 gives the report on number of sources and each source.

Stage 2 can take literally hours on one data source and the application allows for saving current state to allow it to be stopped and continued later.

Therefore I've written the script to allow the job(s) to run but with a CTR-c function script that allows the user to either kill the whole job, or to kill just the current dataset.

However this function script is falling over and I can't see why.

Here's the function script....

Code:
trapcatch ()  { echo "Ctl-c Detected, what do you want to do?"
  echo "Please choose the number of one of the following options"
  echo "1.  Jump past this Set"
  echo "2.  Exit altogether"
  echo "Any other key or no key just continues"

  read -t 5 -p "Choose option 1-3 now : " KEYHIT

  case $KEYHIT in
  1*) Echo "OK, I'll bypass this Set then"
      continue 2
      ;;
  2*) Echo "OK, I'll exit gracefully then"
      # need to add the graceful exit here
      exit 99
      ;;
  *)  Echo "OK I'll just carry on then......"
      ;;
  esac    }

Here's the script section that calls the function

Code:
trap trapcatch SIGINT SIGTERM

Here's the output I'm getting when I press CTR-c

Code:
^CCtl-c Detected, what do you want to do?
Please choose the number of one of the following options
1.  Jump past this Set
2.  Exit altogether
Any other key or no key just continues
/usr/sbin/sourceslist.ver0.99: line 1: Echo: not found
/usr/sbin/sourceslist.ver0.99: let: line 1: arithmetic syntax error

I'm guessing the issue maybe to do with the continue 2 command in the script (the trap call happens inside a double loop that loops till a condition is met that moves the script onto the next dataset)

All helpful ideas appreciated.....

Last edited by tesser; 08-23-2012 at 11:12 AM.. Reason: typo
# 2  
Old 08-23-2012
1) Surely "Echo" should be lower case "echo" ?

2) No idea about the "let" because none of the code posted contains "let".
This User Gave Thanks to methyl For This Post:
# 3  
Old 08-23-2012
Quote:
Originally Posted by methyl
1) Surely "Echo" should be lower case "echo" ?

2) No idea about the "let" because none of the code posted contains "let".
Jees....sometimes you just spend far too long in front of a screen, total brain*art on my part.

Having fixed that though the read statement is not outputting the Choose 1-3 option, any ideas why? The syntax of the read looks OK to me.

Thanks

---------- Post updated at 04:11 PM ---------- Previous update was at 03:23 PM ----------

Actually I'm going to post this new problem in a new thread as the original problem for this thread is showing fixed.
# 4  
Old 08-23-2012
Sorry, I don't have a Shell where that syntax of read is valid.

While tinkering I had to change it to:
Code:
echo "Choose option 1-3 now : \c"; read KEYHIT

(My echo is the one which doesn't have the "-n" option).
# 5  
Old 08-23-2012
For echo's that don't have the \c option, the printf builtin ought to work the same in nearly any shell:
Code:
printf "%s" "Choose option 1-3 now : "

# 6  
Old 08-23-2012
Not sure if ash supports 'select', but it might ease the menu creation and execution.
# 7  
Old 08-23-2012
Quote:
Originally Posted by vgersh99
Not sure if ash supports 'select', but it might ease the menu creation and execution.
It doesn't unfortunately.

But since it supports functions, something similar can be built:

Code:
$ cat bb-select.sh

#!/bin/bb

bbselect () {
        local FS="$IFS";        IFS="|" # Split on pipes
        local VAR="$1";         shift   # Get var to save in
        local TITLES="$*"               # TITLES="title1|title2|title3"
        local N=1

        while [ "$#" -gt 0 ]            # Print all titles
        do
                printf "%2d)\t%s\n" "$N" "$1"
                let N=N+1;      shift
        done

        set -- $TITLES                  # $1="title1", $2="title2", ...
        IFS="$FS"                       # Put old splitter back

        read -p "? " REPLY < /dev/tty || return 1

        # Return error when given a non-number
        case "$REPLY" in
        [1-9])  ;;      [0-9][0-9])     ;;
        *)              return 1        ;;
        esac

        # Return error when given an out-of-range number
        [ "$REPLY" -lt 1 ]  && return 1
        [ "$REPLY" -gt $# ] && return 1

        # Look up the correct title text
        let N=REPLY-1
        [ "$N" -gt 0 ] && shift "$N"

        # Put the title text in the variable *named* in VAR
        read $VAR <<EOF
$1
EOF
        # Return success
        return 0
}

while ! bbselect X "Door 1" "Door 2" "Door 3"
do
        echo "Invalid reply $REPLY"
done

echo "Got value '$X' -- number $REPLY"

$ ./bb-select.sh

 1)     Door 1
 2)     Door 2
 3)     Door 3
? 0
Invalid reply 0
 1)     Door 1
 2)     Door 2
 3)     Door 3
? 50
Invalid reply 50
 1)     Door 1
 2)     Door 2
 3)     Door 3
? slartibartfast
Invalid reply slartibartfast
 1)     Door 1
 2)     Door 2
 3)     Door 3
? 3
Got value 'Door 3' -- number 3

$


Last edited by Corona688; 08-23-2012 at 01:40 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Pipe causing last command error to not function

Hi I am quite new to scripting and cannot work out how to do the following - I want to pipe to a log file and then use the "last statement error" in an if statement after, and this doesn't work because it checks the pipe statement instead of the script. Example: executteTheScript $var |... (4 Replies)
Discussion started by: erjorgito
4 Replies

2. Shell Programming and Scripting

Help with FTP Script which is causing "syntax error: unexpected end of file" Error

Hi All, Please hav a look at the below peice of script and let me know if there are any syntax errors. i found that the below peice of Script is causing issue. when i use SFTP its working fine, but there is a demand to use FTP only. please find below code and explain if anything is wrong... (1 Reply)
Discussion started by: mahi_mayu069
1 Replies

3. Shell Programming and Scripting

Bash function accepting list of strings and error message

I have a variable strLst containing a list of strings. I want to create a function that takes the list and an error message. If the number of strings is 0 or greater than 1, I print the error message. (1 Reply)
Discussion started by: kristinu
1 Replies

4. Shell Programming and Scripting

Spaced input causing awk error

Hi all, Just want to say thanks for the great forum you have here, the old topics and posts have helped tremendously. So much so that I have managed to figure a lot out just by researching. However, I'm having a small issue that I simply can't find the answer to. (4 Replies)
Discussion started by: whyte_rhyno
4 Replies

5. UNIX for Dummies Questions & Answers

How to get failure notice message when email is not sent.

I am using mailx command to send emails from the Unix command prompt. Whenever email is not sent it is not giving me any message "Email not sent" or failure delivery notice for the wrong email addresses. When I give correct email address I am able to receive them correctly. Can anyone please... (0 Replies)
Discussion started by: szc0025
0 Replies

6. Shell Programming and Scripting

SendMail Function Failure

Hi All, Background: We use SendMail function (given below) to send emails to users. The email address are obtained as ouptut of a stored procedure in sybase. We have defined a SendMail function as below in a .pm file and it is used in a .pl script. Code Snippet: sub SendMail { ... (1 Reply)
Discussion started by: vigdmab
1 Replies

7. Shell Programming and Scripting

Function not found message

I have shell script as below: #!/bin/ksh #set -xv function set_variable { VARIABLE_NAME=$1 CURRENT_PATH=`pwd` if ; then echo "\nconfiguration_file.lst file not found in $CURRENT_PATH/common/common_scripts" exit 1; fi VARIABLE_COUNT=`cat... (2 Replies)
Discussion started by: findprakash
2 Replies

8. Solaris

error message rmclomv ... SC Login Failure for user Please login:

Hello World ~ HW : SUN Fire V240 OS : Solaris 8 Error message prompts 'rmclomv ... SC login failure ...' on terminal. and Error Message prompts continually 'SC Login Failure for user Please login:' on Single Mode(init S) The System is in normal operation, though In case of rain, Can... (1 Reply)
Discussion started by: lifegeek
1 Replies

9. Solaris

Memory error causing reboot

Hi there I have a box that at 4pm started recieving soft errors on a DIMM, normally this is ok and we have time to swap it out. But I got the following error which caused the box to reboot NOTE: there were abount 6 or 7 normal "soft error encountered" messages before this one Nov 7... (1 Reply)
Discussion started by: hcclnoodles
1 Replies

10. Solaris

Explorer causing syslog error

Hi there, I have upgraded my explorer (SUNWexplo) on a solaris 10 Sparc box from version 3.4 to the latest version (5.5) . However im a little concerned, whenever I run the new explorer either manually or scheduled, I get a syslog event as follows 1 in 0:08:31: Sep 22 17:00:15 fmy.machine.com... (8 Replies)
Discussion started by: hcclnoodles
8 Replies
Login or Register to Ask a Question