Need help implementing a timout in my Shell Script for RHEL6


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help implementing a timout in my Shell Script for RHEL6
# 1  
Old 07-30-2014
Need help implementing a timout in my Shell Script for RHEL6

Hey Guys,

My problem:

I have a script that will be querying the database every minute to see if it gets a response, the response its querying for is "UP" in a table i made called dbup in the database.

Now, I am trying to add the component to implement a timeout if the script does not get a response from the server and skip to next line etc.

I would like to implement it either at the DB layer because of issues we have had with the product.


We want to skip the -->

I assign the variable query_select1, before I query DB to assign it to STRING "UP.

Code:
query_select1="down"
-->query_select1= ##QUERY SELECT FROM DB String "UP"##


Any help would be appreciated. NOTE: we would like to avoid killing the script, but if necessary I might be ok with killing it and then sending message to myself that process got killed this is why.
But I really could use a solution to this because When the variable ="down" stays the same and doesn't get changed to "UP" from Database, then it gets passed onto the auto generated emails we have setup.

If there are other methods that I haven't thought of let me know as well.



RHEL6

Last edited by mo_VERTICASQL; 07-30-2014 at 12:37 PM..
# 2  
Old 07-30-2014
You can have subshells that watch each other, so if the query loop has not written a new output to the output file for N seconds, another looping watcher can decide it is hung and kill and restart it. A third looping watcher-publisher can declare it down until there is a fresh 'up', and vice versa, and publish the status and status changes.
# 3  
Old 07-30-2014
Ideally, I would like to implement less watcher scripts as a best practice (This is an enterprise environment)

and the script I am going to implement will run every minute so it might be an unnecessary load to do what you suggest.

If I am wrong or my assumptions in correct let me know.

and FYI, the script will be scheduled to run every 1 minute, in background.
It has a LOT of temporary variables too -so the cleanup process more complicated.

---------- Post updated at 12:03 PM ---------- Previous update was at 12:00 PM ----------

also I found this googling,

is this something that might work or no?


Code:
trap 'echo script_timeout ; exit ' USR1   
wait_n_sig() {    sleep $2    [ -d /proc/$1 ] && kill -s USR1 $1 }   
timeout() {    wait_n_sig $$ $1 & }   
timeout 5 read -p "Name: " name echo "Your name is " $name

---------- Post updated at 12:06 PM ---------- Previous update was at 12:03 PM ----------

DGPICKETT, for the watcher script you describe can you expand on the logic for me I am bit of an intermediate shell guy.

like I mean if its not too much could you expand:
1.....
2.....
3....

in terms of what you mean.

Thanks!

---------- Post updated at 12:14 PM ---------- Previous update was at 12:06 PM ----------

If I implement in my subshell the script running too long kill and email its just basically this right:
-----------------------------
(
##If runs for this time
##KILL MAIN.sh
##EMAIL NOTICE
)

MAIN.SH
------------------------------

---------- Post updated at 12:46 PM ---------- Previous update was at 12:14 PM ----------

Will this do as the watcher subshell ?


Code:
( sleep 20 ) & pid=$! ( sleep 2 && kill -HUP $pid ) 2>/dev/null & watcher=$! if wait $pid 2>/dev/null; then     echo "your_command finished"     pkill -HUP -P $watcher     wait $watcher else     echo "your_command interrupted" fi


Last edited by Franklin52; 07-30-2014 at 03:01 PM.. Reason: fixed tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Implementing linked list in shell scripting

Hello Experts, Is it possible to implement linked list in shell scripting? is yes then how can we do it? Any working example is highly appreciated. Thanks in advance. (4 Replies)
Discussion started by: mukulverma2408
4 Replies

2. Shell Programming and Scripting

Implementing Listagg like function in shell

Hi, Basically what I am trying to do is making multiple fields of the same type comma-separated. i.e. for a data like this: B00000 abc B00001 abc,def B00001 ghi B00001 jkl B00002 abc B00002 def B00003 xyz Output should be like: B00000 abc B00001 abc,def,ghi,jkl... (20 Replies)
Discussion started by: prohank
20 Replies

3. Shell Programming and Scripting

Help with implementing available memory status script

hi , i want write the script which automatically send an alert mail to my mail id when there is low memory available. things which i am able to implement -: i got the output of current memory status into one file . Than i break down the required coloumn and again send it in another file. My... (1 Reply)
Discussion started by: abhinav dixit
1 Replies

4. Shell Programming and Scripting

Implementing Queue Using Shell scripts

HI I want to implement a control mechanism using Shell scripts .The intention is to have controlled number of jobs running in parallel External process will kickstart 40 jobs in parallel .All the 40 jobs will call the same generic script with different parameter values .But at a... (4 Replies)
Discussion started by: police
4 Replies

5. Homework & Coursework Questions

implementing mkdir, chdir, mv, pwd inside a shell !

1. The problem statement, all variables and given/known data: need to implement mkdir, chdir, mv, pwd given a shell.cpp directory.cpp and some other files this shell missing these commands, and i need to implement them inside the shell 2. Relevant commands, code, scripts,... (0 Replies)
Discussion started by: evantheking
0 Replies

6. Programming

Implementing a shell in C

Hi, I am implementing a shell in C, with the following problem... Suppose the shell is invoked from the command line as >> myshell < test.in > test.out 2>&1 I have to execute the commands in test.in and redirect them to test.out How does one detect in the main function that the shell... (1 Reply)
Discussion started by: jacques83
1 Replies

7. Programming

need help in implementing simple interactive shell in C

hello all, i hv attached herewith my program to implement a simple interactive shell in C. no matter hw hard I try, I keep getting some errors. i need help - urgently !! proj1test7.c: In function `parseCommand': proj1test7.c:102: warning: assignment makes pointer from integer without a cast... (2 Replies)
Discussion started by: nix1209
2 Replies

8. Programming

Implementing a shell

I'm implementing a shell in C that supports piping, output redirection, and background processing, and a few other commands. I was wondering how I'd go about implementing the output redirection. So, I'd open a file and I'd fork and execute the command. But how would I get stdout into the file? Any... (10 Replies)
Discussion started by: ununium
10 Replies

9. UNIX for Dummies Questions & Answers

Telnet timout question

ok here is a little bit on what I am trying to do. I am logged into a saolaris 9 server and telnet to another server to run an application that sits on the second unix / linux server. This application can sit idle for an hour to two and any given time. During this time the telnet session timesout... (4 Replies)
Discussion started by: Acleoma
4 Replies

10. IP Networking

tcp timout

I am led to understand that there when a port is bound for a tcp connection...once that connection is closed there is a timeout period before that port can be reused ... and the software I am using shows that. How long is this timeout - what affects it and is there anyway to reuce the timeout? (5 Replies)
Discussion started by: peter.herlihy
5 Replies
Login or Register to Ask a Question