whi
whi

Reputation: 2750

how to timeout a linux script

coreutils timeout and other timeout script i searched, they apply for a CDM
but i'd like to apply timeout for a linux script, if not finished for a period. like:

cd XXX && CMD && sleep 3 && kill -0 XX  

How to do it?

Upvotes: 1

Views: 1012

Answers (1)

Christophe Biocca
Christophe Biocca

Reputation: 3468

You can pass the spawning of a subshell to timeout, and have the subshell run the code that needs to be timed out:

#!/bin/bash
timeout 5 bash -c "ping google.com -c 2; ping yahoo.com -c 10"

If you clarify what you need exactly there may be cleaner ways to achieve this.

Upvotes: 3

Related Questions