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