Re: [bash] running script for specific time



On Tue, 22 Apr 2008 19:53:29 +0000, Jahoo wrote:

Hello
I would like to make script which:
will execute specific command (for example tcpdump, tail or something
like that - with some grep or cut pipes...) - it's of course easy BUT
i would like this command to be executed for specific time, for example
an hour and after that it should be stopped.

Can You help me one more time? :>

Not tested:
----8<--- cut here ---8<----
#!/bin/bash
timeout=$1
shift
("$@") &
sleep $timeout
kill -s TERM $!
----8<--- cut here ---8<----
Put the lines above in a file called do-for-seconds, make the file
executable, and run like this

$ ./do-for-seconds 3600 tcpdump -a -b -c otherargs

Regards
.



Relevant Pages