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
script(1)							   User Commands							 script(1)

NAME
script - make record of a terminal session SYNOPSIS
script [-a] [filename] DESCRIPTION
The script utility makes a record of everything printed on your screen. The record is written to filename. If no file name is given, the record is saved in the file typescript. See WARNINGS. The script command forks and creates a sub-shell, according to the value of $SHELL, and records the text from this session. The script ends when the forked shell exits or when Control-d is typed. OPTIONS
The following option is supported: -a Appends the session record to filename, rather than overwriting it. NOTES
script places everything that appears on the screen in filename, including prompts. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ |CSI |Enabled | +-----------------------------+-----------------------------+ SEE ALSO
attributes(5) WARNINGS
script can pose a security risk when used in directories that are writable by other users (for example, /tmp), especially when run by a privileged user, that is, root. Be sure that typescript is not a link before running script. SunOS 5.10 30 Jan 2004 script(1)