Hey drop us a line about the show. Feel free to ask questions, provide feedback and criticism, or just ramble on about anything your little heart desires.
Moderators: snarkout, Patrick, dann
-
hellonorman
- Posts: 267
- Joined: Wed Dec 28, 2005 11:08 pm
Post
by hellonorman » Fri Feb 22, 2008 1:35 am
I capture things manually from time to time from my dvr through my wintv 150 with the manual command
Anyone know the simplest way I could have this command run for a certain number of minutes and then terminate?
"It's not a lie, if you really believe it"
--George Costanza
-
adam
- Posts: 73
- Joined: Sat Jun 03, 2006 4:43 pm
- Location: Dora, Alabama
Post
by adam » Fri Feb 22, 2008 2:50 am
you could do something like:
Code: Select all
cat /dev/video0 > filename.mpg &
sleep 100
kill $!
just replace 100 with the amount of seconds you want to run. you can also do
Code: Select all
#for 10 minutes
sleep 10m
#for 1 hour
sleep 1h
#or even 1 day
sleep 1d
and FYI, bash replaces $! with the process id of the cat command.
-
snarkout
- Site Admin
- Posts: 1342
- Joined: Tue Aug 16, 2005 9:35 pm
Post
by snarkout » Fri Feb 22, 2008 10:34 am
I've used at for this sort of thing in the past.
Shared pain is lessened, shared joy is increased; thus do we refute entropy.
--Spider Robinson
-
hellonorman
- Posts: 267
- Joined: Wed Dec 28, 2005 11:08 pm
Post
by hellonorman » Fri Feb 22, 2008 3:11 pm
Hey thanks I had found this little script last night which is basically the same thing you wrote:
Code: Select all
#!/bin/bash
sleep 1h # Instead of using sleep here, you can start the script by using
# the at command, see 'man at'.
cat /dev/video0 > /home/mythtv/video/myvideo.mpg &
CAT_PID=$!
# $! is PID of last job running in background.
sleep 30m
# You should add some check here to make sure cat is still running,
# otherwise you might accidentally kill some other process.
kill $CAT_PID
I took out the beginning sleep because I didn't need it. I also added some variables so I could just pass in the filename and time:
Code: Select all
#!/bin/bash
cat /dev/video0 > ~/$1.mpg &
CAT_PID=$!
# $! is PID of last job running in background.
sleep $2m
# You should add some check here to make sure cat is still running,
# otherwise you might accidentally kill some other process.
kill $CAT_PID
I saw some at command examples but I am generally manually starting a recorded program from my dvr so it's easier to just use the script.
The comments speak of checking for the cat command so you don't kill some other process.
Would the cat PID really get reused? How would the some other process get that same pid?
"It's not a lie, if you really believe it"
--George Costanza
-
adam
- Posts: 73
- Joined: Sat Jun 03, 2006 4:43 pm
- Location: Dora, Alabama
Post
by adam » Fri Feb 22, 2008 6:20 pm
In such a small script, you don't even need to store the pid in an external variable. Only when a program is run in the backgroud is its pid stored in $!. Not that it hurts to do so anyway

.
hellonorman wrote:The comments speak of checking for the cat command so you don't kill some other process.
Would the cat PID really get reused? How would the some other process get that same pid?
If cat dies for some reason, that pid number is freed up and can be randomly selected again. Not likely, but possible.