Find the answer to your Linux question:
Results 1 to 2 of 2
First of all, thanks to all the great people here who have provided such great help. These forums are fantastic. I have a hauppauge PVR 150 TV capture card. To ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Mar 2005
    Posts
    38

    Killing a process after a fixed time


    First of all, thanks to all the great people here who have provided such great help. These forums are fantastic.

    I have a hauppauge PVR 150 TV capture card. To capture video is quite simple. Simply type: cat /dev/video > mymovie.mpg

    and hit ctrl-c when done.

    This is great. However, what would be nicer is if I could have a simple bash script that I could pass in a time period that it would kill the capture automatically.

    So I could do something like: record mymovie.mpg 120

    where 120 is the number of minutes to record. It wouldn't even have to be minutes. Even better would be something like 1:55:00. But regardless, of how the parameter is handled, I simply want an easy to use script that will kill the process after a fixed time.

    My main issue is that I have to remember to cancel it and sometimes I forget for an hour or two and it eats up a lot of hard drive space.

    Anyway, could someone explain how I'd do this from a script?

    On a somewhat related issue, I do the recordings from a telnet terminal (the machine is in another room). Occasionally the connection gets severed (usually because of some flakey VPN software I have to use) and when it does, sometimes my executing command gets canceled. It would be best if I could execute all of this in some sort of state that it's disconnected from the terminal. Is there some way to execute commands that way? Would doing ctrl-z and bg accomplish that for me or is the process still attached to the terminal?

    Thanks in advance.

    Pete

  2. #2
    Just Joined!
    Join Date
    Mar 2005
    Posts
    38
    I found a working solution... Just in case anyone's interested, this is it:

    #!/bin/bash

    if [ $# != 2 ]; then
    echo "Usage: capture filename.mpg mins"
    exit 1
    fi

    cat /dev/video > $1 &

    let "mins=$2 * 60"

    sleep $mins

    kill -9 $!

    * edited to accept minutes instead of seconds as the second parameter

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •