Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Timing a script

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 01-25-2013
SkySmart SkySmart is offline
Registered User
 
Join Date: Dec 2006
Last Activity: 11 May 2015, 5:08 PM EDT
Posts: 677
Thanks: 445
Thanked 2 Times in 2 Posts
Timing a script

i have a very big script i have that i'd like to add a timeout to.

this script runs on a several remote host. i update this script with timeout clause and then copy it over to all the hosts on which it is currently on.

basically, i want the timeout to make the script abort/exit if it's running time is beyond a predeffined time.

this is a script written in bash.

i'm hoping something like this is possible.


Code:
#!/bin/bash

timeout 60seconds () {

.......
........
.........
........
.........
.......
.......

}

if [ timeout -ge 60 ]
exit
fi

Sponsored Links
    #2  
Old Unix and Linux 01-25-2013
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 4 September 2015, 6:15 AM EDT
Location: San Jose, CA, USA
Posts: 7,096
Thanks: 300
Thanked 2,343 Times in 2,007 Posts
Using a recent Korn shell, the following seems to do what you want:

Code:
#!/bin/ksh
st=$SECONDS
 ... ... ...
if (( SECONDS - st > 60 ))
then    exit
fi

Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Challenging task : script for mailing process completion timing report to users. ammbhhar Shell Programming and Scripting 0 12-02-2010 12:46 AM
Timing out lynx request in a bash script lowmaster Shell Programming and Scripting 1 05-21-2009 11:19 AM
timing your functions bebop1111116 Programming 3 11-01-2006 03:19 PM
Timing out a SSH rcunn87 Shell Programming and Scripting 9 07-31-2006 05:11 PM
HTML display timing problem under ksh script Nicol Shell Programming and Scripting 1 10-28-2003 01:51 PM



All times are GMT -4. The time now is 08:23 AM.