Alert for long running commands in script

Hi All,

Is there a way in which a long running command can terminate by itself inside a script? I need something like below:

echo Start
<command>
exit

If the <command> is taking more than say 100 seconds to complete, the script should exit without manual intervention.

Thanks,
Deepak

Hi.

Yes, provided you are using a shell and system that allows limit control. For example, in bash:

ulimit: ulimit [-SHacdfilmnpqstuvx] [limit]
    Ulimit provides control over the resources available to processes
    started by the shell, on systems that allow such control.  If an
    option is given, it is interpreted as follows:
    
        -S      use the `soft' resource limit
        -H      use the `hard' resource limit
        -a      all current limits are reported
        -c      the maximum size of core files created
...
        -t      the maximum amount of cpu time in seconds
...

-- excerpt from man bash

Best wishes ... cheers, drl

or, put the command in background. Wait for X seconds, and check whether it is completed, else kill it.