Python script help. Kill binary on timeout


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Python script help. Kill binary on timeout
# 1  
Old 03-16-2011
Python script help. Kill binary on timeout

This is part of my script, as you can see when the alarm is raised it shows some text, what I need it to do is to actually kill the binary "test" (TEST_PATH) when the timeout happens.


Code:
#!/usr/bin/python26

from optparse import OptionParser

import nagios
import re
import subprocess
import commands
import signal
import time

...
...
...

class Alarm(Exception):
    pass

def alarm_handler(signum, frame):
    raise Alarm

signal.signal(signal.SIGALRM, alarm_handler)
signal.alarm(120)  # 2 minutes

def check_login(serviceName, rdir, masterAcct, persona, passwd):
    cmd = TEST_PATH + ' -s ' + serviceName + ' -r ' + rdir + \
          ' -m ' + masterAcct + ' -p ' + persona + ' -P ' + passwd

  

 try:
                        status, info, prof = check_login(options.serviceName, options.rdir, options.masterAcct,
 options.persona, options.passwd)
                        signal.alarm(0)
                except Alarm:
                        status = nagios.STATUS_WARN
                        info = 'test timed out!'
                        prof = ''

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Windows & DOS: Issues & Discussions

How to execute python script on remote with python way..?

Hi all, I am trying to run below python code for connecting remote windows machine from unix to run an python file exist on that remote windows machine.. Below is the code I am trying: #!/usr/bin/env python import wmi c = wmi.WMI("xxxxx", user="xxxx", password="xxxxxxx")... (1 Reply)
Discussion started by: onenessboy
1 Replies

2. Shell Programming and Scripting

Adding a timeout when using sftp in a script?

Hello guys. I need some help. First of all, sorry about my english, that is not my native languaje. I have a bash script in Solaris with the next lines: And the sftp.sh has this: The problem is that sometimes the sftp takes a long of time. I mean, 2 or 3 hours when it should... (12 Replies)
Discussion started by: giolita25
12 Replies

3. Shell Programming and Scripting

Python Binary File Read and Parse

Hi to everyone :), i have a challenge right now in python that for now needs a bit of help in one part of the c0de. The task is create a new file with the name of the file defined by the ASCII content between the 3 byte and the 16 byte that is parsed from the binary file, the file is over 20 Mb i... (0 Replies)
Discussion started by: drd0spt
0 Replies

4. Shell Programming and Scripting

Script in python to kill process by date

Hello everyone, First sorry for my english. I'm new in python and I want to create a script that allows the cleaning of a directory (/ tmp), files corresponds to a specific process according to the date. Steps: 1 - I have to find all processes of a program running, eg OpenOffice,... (0 Replies)
Discussion started by: doudoubens
0 Replies

5. Shell Programming and Scripting

Command timeout from inside script.

Hi, I've written a very robust script to get an external IP address from 'behind' a router. It uses many web pages randomly choosing which one/ones to use at run time. The "fetch the web page containing the IP address" is handled by either wget or curl both of which have their 'max time for the... (6 Replies)
Discussion started by: gencon
6 Replies

6. Shell Programming and Scripting

kill process if timeout Python

I have a python script that calls a binary. I want to make sure that if the binary fails (with a 2 min timeout) it kills the process. Currently I'm unable to do that as I only kill the function but the binary is still running. Please help #!/usr/bin/python26 from optparse import OptionParser... (0 Replies)
Discussion started by: erick_tuk
0 Replies

7. Shell Programming and Scripting

session timeout for shell script

I am executing test.sh script. But this script takes lot of time and in the meantime the shell timeouts without completing the script. Is there any command which will continue processing the script. Thanks (3 Replies)
Discussion started by: infyanurag
3 Replies

8. Shell Programming and Scripting

read from std i/p with timeout within a script

hello every one , this is my first participation in the forum , I hope it'll be a good start within a script I would like to put some code to read i\p from standard i\p using read command if it reads Y it will terminate the script if it reads N it will continue execution , if no i\p is... (2 Replies)
Discussion started by: Blue_shadow
2 Replies

9. UNIX for Dummies Questions & Answers

wget --dns-timeout script

#!/bin/sh # 'clear' for i in $(seq -w 15 37); do echo $i wget --dns-timeout=0.0001 http://napdweb${i}.eao.abn-iad.ea.com:8000/webcore/test/test.jsp -o 1 A=`cat 1` C=$(expr "$A" :... (1 Reply)
Discussion started by: veerumahanthi41
1 Replies

10. Shell Programming and Scripting

Can a timeout be specified in a shell script?

Hi, I have to develop a shell script which exits after <n> minutes. For e.g. The user is taking too much time to enter an input, and the script will terminate after 10 minutes pass by. Is this possible ? Thanks, Puneet (3 Replies)
Discussion started by: puneetarora_12
3 Replies
Login or Register to Ask a Question
PYTHON-COVERAGE(1)					      General Commands Manual						PYTHON-COVERAGE(1)

NAME
python-coverage - measure code coverage of Python program execution SYNOPSIS
python-coverage -x module.py [ARG...] python-coverage -e python-coverage -r [-m] python-coverage -a [file...] DESCRIPTION
python-coverage executes a Python program and measures which of its statements are executed and which are not. It stores the information in the file .coverage in the current working directory. OPTIONS
-e Erase the .coverage file. -x Execute a Python module, giving it the remaining command line arguments. -r Produce a coverage report. -m With -r, show the line numbers that were missed by the execution. -a Annotate source files. For each source file foo, produce foo,cover, with executed lines prefixed by ">" and non-executed by "!". --help Produce a help summary. It might be more helpful than this manual page. AUTHOR
The python-coverage command is a one-line Python script which calls the coverage.py Python module to do all the work. The module was rigi- nally developed by Gareth Rees, and is now developed by Ned Batchelder. The module's home page is http://www.nedbatchelder.com/code/modules/coverage.html. This manual page was cobbled together by Lars Wirzenius for Debian, by copy-pasting from the help texts from the module. PYTHON-COVERAGE(1)