Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I want know how I can run a command for a specified time say, one minute and if it doesn't complete execution then I should be able to stop it.

share|improve this question
add comment

1 Answer 1

up vote 19 down vote accepted

Use timeout:

NAME
       timeout - run a command with a time limit

SYNOPSIS
       timeout [OPTION] DURATION COMMAND [ARG]...
       timeout [OPTION]

(Just in case, if you don't have this command or if you need to be compatible with very very old shells and have several other utterly specific requirements… have a look at this this question ;-))

share|improve this answer
    
Perfect, thanks for linking to that question. I didn't have timeout on my system but I do now. Just on a side note, is timeout bundled with the majority of linux distributions? –  nikhil Oct 24 '11 at 4:28
    
Pretty cool. you can do something like this: for i in `seq 0 3`; do timeout 2 ethtool -p eth$i; done; to blink LED's on NIC's –  user1527227 Jun 19 at 16:42
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.