To run a shell script for a definite period

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting To run a shell script for a definite period
# 1  
Old 09-07-2009
To run a shell script for a definite period


I would like to invoke a shell script with period (in seconds) as a parameter and want it to run olny for that period. The script should come out after that period even some work is going inside the script.

# 2  
Old 09-07-2009
I don't know if any shell has a built-in facility to timeout a command but in perl, for example, "alarm x" will interrupt the process after x seconds by sending a SIGALRM signal.

---------- Post updated at 10:59 PM ---------- Previous update was at 10:40 PM ----------

To do this with the shell, or some scripting language that does not have an alarm function, you will need to code your program so that it starts another background process (which you will pass your pid and the timeout value). It should sleep for the required period and then, when it wakes up from sleep, it should kill the parent program.
# 3  
Old 09-07-2009
I remember that this question had been answered already.
Did you try searching for it?

Here is a start,
start the process in background
get the pid using $!
sleep for 'duration' && kill -2 <using_the_above_pid>

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script run in a case statement call to run a php file, also Perl

Linux System having all Perl, Python, PHP (and Ruby) installed From a Shell script, can call a Perl, Python, PHP (or Ruby ?) file eg eg a Shell script run in a case statement call to run a php file, also Perl or/and Python file??? Like #!/usr/bin/bash .... .... case $INPUT_STRING... (1 Reply)
Discussion started by: hoyanet
1 Replies

2. Shell Programming and Scripting

Script Shell: Diplay date of two minutes (period)

Hi all, Here is my script: #!/bin/sh while :; do sleep 1 date done Please, how can i change this script, i'd like to display the time only of two minutes (period) and exit ? Is that possible ? Thank you so much for help. Bests... (3 Replies)
Discussion started by: chercheur111
3 Replies

3. Shell Programming and Scripting

Run a shell script from one host which connext to remote host and run the commands

I want to write a script which would run from one host say A and connect to other remote host B and then run rest of commands in that host. I tried connecting from A host to B with SSH but after connecting to host B it just getting me inside Host B command prompt. Rest of the script is not running... (6 Replies)
Discussion started by: SN2009
6 Replies

4. Shell Programming and Scripting

How to run cmds after changing to a new env (shell) in a shell script

Hi, I am using HP-UNIX. I have a requirement as below I have to change env twice like: cadenv <env> cadenv <env> ccm start -d /dbpath ccm tar -xvf *.tar ccm rcv .... mv *.tar BACKUP but after I do the first cadenv <env> , I am unable to execute any of the later commands . ... (6 Replies)
Discussion started by: charlei
6 Replies

5. Shell Programming and Scripting

Help need to make a shell script run for ffmpeg vhook watermaking in shell

i have a small problem getting a batxh shell script to run in shell this is the code the problem seems to be centered around the ffmpeg command, something maybe to do with the ' ' wrapping around the vhook part command this is a strange problem , if i take the ffmpeg command and... (1 Reply)
Discussion started by: wingchun22
1 Replies

6. Shell Programming and Scripting

How to Run a shell script from Perl script in Parent shell?

Hi Perl/UNIX experts, I have a problem in running a shell script from my perl script ( I run the perl script using perl from the shell prompt The shell script picks the files in "input" folder and procesess it. The shell script has this code. export... (16 Replies)
Discussion started by: hifake
16 Replies

7. Shell Programming and Scripting

UNIX Shell script to chec timeout period when collecting files in directory - HELP

Hi, I have a shell script which is to perform a check if all 4 particular type of files exists in a directory. If ALL 4 files are present within a specific Timeframe, then tar these files and zip it. If not all 4 files are present in the directory after the specific timeframe, then tar... (1 Reply)
Discussion started by: Danny Fang
1 Replies

8. Shell Programming and Scripting

Run job for a period of time

I have a job that runs for an unspecified amount of time. I want to run this as a cron job for a specified amount of time, say 2 hours. Once the time is up, the program should be killed in the middle of execution. How can I do this? Thanks. (5 Replies)
Discussion started by: cooldude
5 Replies

9. Shell Programming and Scripting

How to run unix commands in a new shell inside a shell script?

Hi , I am having one situation in which I need to run some simple unix commands after doing "chroot" command in a shell script. Which in turn creates a new shell. So scenario is that - I need to have one shell script which is ran as a part of crontab - in this shell script I need to do a... (2 Replies)
Discussion started by: hkapil
2 Replies
Login or Register to Ask a Question