Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am making bash script for my use. How can i run a command for certain time, like 20 second and terminate command? I tried a lot of solutions but nothing works, I also tried timeout command with no success. Please give me some solution for this.

for example: I want to run this command in script and terminal after 10 sec

some command
share|improve this question

3 Answers 3

Hm, that should do the trick:

xmessage "Hello World" &
pidsave=$!
sleep 10; kill $pidsave

xmessage provides a quick test case here (in your case the airodump command should go there); & puts it into background.

$! holds the PID of the last started process (see e.g. http://stackoverflow.com/a/1822042/2037712); the PID gets saved into the variable pidsave.

After some waiting (sleep), send a TERM signal to the process.

share|improve this answer
    
Thanks buddy it works but Now I have 1 problem. I want to see output which is created by command but xmessage windows doesn't show anything. –  Umair Riaz May 8 '13 at 17:51
    
problem solved. Thanks guys –  Umair Riaz May 8 '13 at 18:13
    
@UmairRiaz: xmessage was just an example. To adapt your example in the question and log the output of the command use some command > logfile & in the first line. Afterwards you can analyse logfile. –  mpy May 8 '13 at 21:00

I suggest you read the following article

http://www.linuxquestions.org/questions/linux-software-2/bash-script-to-run-commands-for-specified-number-of-seconds-772885/

share|improve this answer
    
no success with that solution –  Umair Riaz May 8 '13 at 11:18
8  
-1. Please don't post link only answers, links die. Instead describe what is suggested in the link in your answer. –  terdon May 8 '13 at 12:35

From the bash prompt you can use"

share|improve this answer

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.