Run for N seconds then kill...
This is REALLY got me stumped..
I'm trying to run a simple bash command for N seconds then force it to kill/stop/halt. The command is: Code:
$ gpspipe -r > nmea.data How can I alter my command to make it do this? I'd prefer to have this as a 'one-liner', but if need be I can create a bash script. Please help! Thanks! |
This should work:
Code:
$ gpspipe -r > nmea.data & sleep 3 ; kill $! |
Sweet beans! Works brilliantly!
Thanks a million, man! :D |
Ok - additional request:
Is there any way to daemonize this? I've tried adding another '&' to the very end (after $!) but this didn't do it. The reason I ask is I'm making a script that uses this command, and the script 'hangs' for the duration of the command. I'd like to be able to run the command and have my script continue on without waiting for the command to finish. Thanks! |
Quote:
Quote:
|
You're a genius, colucix! The -n option did the trick! Too bad I didn't know about it earlier..
Anyways, this is the command I'm using now which works perfectly (ven daemonizes): Code:
gpspipe -r -n 15 > nmea.data & :D |
This would work too:
Code:
cat /dev/random >/dev/null & echo $! | (sleep 3 ; xargs kill) & |
All times are GMT -5. The time now is 11:53 AM. |