Timeout doesn't work, please help me


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Timeout doesn't work, please help me
# 1  
Old 07-06-2015
Timeout doesn't work, please help me

Code:
#!/bin/sh
trap "cleanup" TERM
timeout=5
mainpid=$$
cleanup()
{
    echo "at $i interupt"
    kill -9 0 
}


watchdog()
{
    sleep $1
}


(watchdog $timeout && kill -TERM $mainpid) & 

run_test()
{
for i in `seq 1 100`
do
        sleep 1 
       # i=$((i+1))
    echo "$i,contiuing"
done
}

run_test |tee -a x.log

it doesn't interrupt by the TERM, and I want to print where to interrupt by 'echo $i' can you help me to get where is interrupt

Last edited by yanglei_fage; 07-08-2015 at 04:32 AM..
# 2  
Old 07-07-2015
I removed i=$((i+1)) and I got:

Code:
1,contiuing
2,contiuing
3,contiuing
4,contiuing
at 5 interupt
Killed: 9

What result did you get and what did you expect to get?
# 3  
Old 07-07-2015
Quote:
Originally Posted by Scrutinizer
I removed i=$((i+1)) and I got:

Code:
1,contiuing
2,contiuing
3,contiuing
4,contiuing
at 5 interupt
Killed: 9

What result did you get and what did you expect to get?
after I removed i=$((i+1)), it doesn't work like your side

I want get
after 5s (timeout=5), the script will be stopped and with it's subprocess stopped too, and alos get where it stopped, here is "echo "at $i interupt" to tell where it stopped
# 4  
Old 07-07-2015
OK so what shell are you using, what OS, how do you execute your script and can you post the output of your script.
# 5  
Old 07-07-2015
Quote:
Originally Posted by Scrutinizer
OK so what shell are you using, what OS, how do you execute your script and can you post the output of your script.
I'm on "Ubuntu 12.04.4 LTS \n \l" without terminate running this script
Code:
lyang001@lyang001-OptiPlex-9010:~/nehalem_workdir$ echo $SHELL
/bin/bash

root@lyang001-OptiPlex-9010:/home/lyang001/del# ./zz.sh 
1,contiuing
2,contiuing
3,contiuing
4,contiuing
5,contiuing
6,contiuing
7,contiuing
8,contiuing
9,contiuing
10,contiuing
11,contiuing
12,contiuing
13,contiuing
14,contiuing
......
......

---------- Post updated 07-07-15 at 03:26 AM ---------- Previous update was 07-06-15 at 11:30 PM ----------

if I remove the '|tee x.log', it works, but I really need it
# 6  
Old 07-07-2015
Move the
Code:
mainpid=$$

and its use
Code:
(watchdog $timeout && kill -TERM $mainpid)

into the function
Code:
run_test(){
}

# 7  
Old 07-07-2015
Quote:
Originally Posted by MadeInGermany
Move the
Code:
mainpid=$$

and its use
Code:
(watchdog $timeout && kill -TERM $mainpid)

into the function
Code:
run_test(){
}

it doesn't work. nothing changes
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

-ne 0 doesn't work -le does

Hi, I am using korn shell. until ] do echo "\$# = " $# echo "$1" shift done To the above script, I passed 2 parameters and the program control doesn't enter inside "until" loop. If I change it to until ] then it does work. Why numeric comparison is not working with -ne and works... (3 Replies)
Discussion started by: ab_2010
3 Replies

2. Shell Programming and Scripting

Why my awk doesn't work?

root@SDP_Wildcat_Pass-3-C1:~# cat /proc/driver/rtc rtc_time : 05:29:40 rtc_date : 2014-12-19 alrm_time : 01:51:53 alrm_date : 2014-12-20 alarm_IRQ : no alrm_pending : no update IRQ enabled : no periodic IRQ enabled : no periodic IRQ... (4 Replies)
Discussion started by: yanglei_fage
4 Replies

3. UNIX for Dummies Questions & Answers

Why doesn't this work?

find . -name "05_scripts" -type d -exec mv -f {}/'*.aep\ Logs' {}/.LogFiles \; Returns this failure: mv: rename ./019_0120_WS_WH_gate_insideTEST/05_scripts/*.aep\ Logs to ./019_0120_WS_WH_gate_insideTEST/05_scripts/.LogFiles/*.aep\ Logs: No such file or directory I don't know why it's trying... (4 Replies)
Discussion started by: scribling
4 Replies

4. Shell Programming and Scripting

My if statement doesn't work why?

I have the following and for some reason I can't have two options together. I mean if I choose -u and -p it won't work... why? #!/bin/bash resetTime=1 mytotalTime=0 totalHour=0 totalMin=0 averagemem=0 finalaverage=0 times=0 function usage() { cat << EOF USAGE: $0 file EOF } (10 Replies)
Discussion started by: bashily
10 Replies

5. UNIX for Dummies Questions & Answers

useradd doesn't work! why??

# uname -a Linux localhost.localdomain 2.4.20-8 #1 Thu Mar 13 17:54:28 EST 2003 i686 i686 i386 GNU/Linux # useradd 4141421248 useradd: invalid user name '4141421248' why??? (6 Replies)
Discussion started by: cqlouis
6 Replies

6. UNIX for Advanced & Expert Users

remsh doesn't work

Hi, I need to use remsh inside a ksh script. The script would remsh to another machine (maybe different OS) and then execute commands. A Simple Script: #!/usr/bin/ksh remsh sun7656 -l myuser "cd /user.3/MyFolder; ls -lart" But this gives me the error: permission denied I also... (4 Replies)
Discussion started by: som.nitk
4 Replies

7. UNIX for Dummies Questions & Answers

my make doesn't work

hi I wrote the following makefile, I have just one problem, when i type make clean I get the message make 'clean' is up to date and any obj file is removed from my folder, what's wrong? Thank you CC = cc all: es.o elaboration.o $(CC) -o es es.o elaboration.o elaboration.o:... (0 Replies)
Discussion started by: Puntino
0 Replies

8. UNIX for Dummies Questions & Answers

Script doesn't work, but commands inside work

Howdie everyone... I have a shell script RemoveFiles.sh Inside this file, it only has two commands as below: rm -f ../../reportToday/temp/* rm -f ../../report/* My problem is that when i execute this script, nothing happened. Files remained unremoved. I don't see any error message as it... (2 Replies)
Discussion started by: cheongww
2 Replies

9. Shell Programming and Scripting

sed doesn't work

Hello I' m confused a bit. I want to replace string "&amp" with "&" using this command. sed 's/&amp/&/g' and it doesn't work. Nothing happens. On the other side this works: sed 's/&amp/@/g' or sed 's/&amp/^/g' !!! Can somebody help please? Thanks (3 Replies)
Discussion started by: billy5
3 Replies

10. Shell Programming and Scripting

Why doesn't this work?

cat .servers | while read LINE; do ssh jason@$LINE $1 done exit 1 ./command.ksh "ls -l ~jason" Why does this ONLY iterate on the first server in the list? It's not doing the command on all the servers in the list, what am I missing? Thanks! JP (2 Replies)
Discussion started by: jpeery
2 Replies
Login or Register to Ask a Question