LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-16-2009, 04:31 PM   #1
mitchell2345
Member
 
Registered: Aug 2008
Posts: 55

Rep: Reputation: 16
run script for X mins


hi,

I am recording off my firewire port. Long story but i cant get Mythtv to work yet. I can use test-mpeg2 -r 1 > file.ts. this just dumps the video to disk

How can i create a crontab/script that will run that cmd for a specified time period

ie, start cmd and 22:00 stop at 22:30

Thanks,
Mitchell
 
Old 06-16-2009, 05:08 PM   #2
Trumpen
LQ Newbie
 
Registered: Dec 2008
Location: Italy
Distribution: Debian & Ubuntu
Posts: 11

Rep: Reputation: 0
You can create a script like this:
Code:
#!/bin/bash

command &

sleep 1800 # 30*60 seconds

kill $! # $! contains PID of the last background executed process
If you need more precision you can use a while loop instead of sleep:

Code:
#!/bin/bash

end=$(date -d "+30 minutes" '+%s')

command &

while [ "$(date '+%s')" -lt "$end" ]; do
       sleep 1;
done

kill $!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] run a command automatically after every 10 mins vikas027 Programming 3 08-03-2008 05:37 PM
how to run a schedule in every 2 mins!! rahulrawat Red Hat 7 12-24-2005 06:58 PM
hard crash after 20 mins. every time on first boot reboot and it will run ok bejamin1 Mandriva 5 02-02-2004 12:42 PM
on Network Up Script run? On Battery power run script? v2-ncl Linux - General 0 12-08-2003 09:34 AM
how to set cron job to run every 5 mins? gsbarry Linux - General 7 05-28-2003 12:30 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:12 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration