Boston Linux & Unix (BLU) Home | Calendar | Mail Lists | List Archives | Desktop SIG | Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings
Linux Cafe | Meeting Notes | Blog | Linux Links | Bling | About BLU

BLU Discuss list archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bash trick of the day



Along with the MythTV thing now working, I have a need to record certain 
things from the capture card outside of MythTV (because you need to 
navigate menus to get to the On Demand stuff, etc).  I also record stuff 
from the line in connected to my Sirius radio.  What I needed was a way 
to run a command for a specific length of time, then kill it.  This is 
what I came up with:


--------------------------------------------------------------------
#!/bin/bash
COMMAND=$1
WAIT_MINUTES=$2

function usage {
	echo $1
	echo "Usage:"
	echo "${0} <command to run> <minutes to run for>"
	exit 1
}

if [[ -z "${COMMAND}" ]] ; then
	usage "No command specified"
fi

if [[ -z "${WAIT_MINUTES}" || $WAIT_MINUTES -lt 1 ]] ; then
	usage "No time specified"
fi

echo "Starting command '${COMMAND}'"
${COMMAND} &
NEWPID=$!
echo "PID is ${NEWPID}"
ps -elf | grep ${NEWPID}
date
WAIT_SECONDS=$(($WAIT_MINUTES * 60))
echo "Sleeping ${WAIT_SECONDS} seconds"
sleep ${WAIT_SECONDS}
date
echo "Killing command"
kill ${NEWPID}
echo "Done."
--------------------------------------------------------------------
Yes, I *do* put help screens on small bash scripts I write just for myself.

I can use this in conjunction with "dd if=/dev/video0 
of=mycaptured.mpeg" to capture video for a given time, for instance.

You likee?

Oh, BTW, did I ever mention the great Bash tips site 
http://bashcurescancer.com/
I think that claim is kinda overrated, but it's a good source of 
information on cool bash programming nonetheless.



-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.





BLU is a member of BostonUserGroups
BLU is a member of BostonUserGroups
We also thank MIT for the use of their facilities.

Valid HTML 4.01! Valid CSS!



Boston Linux & Unix / webmaster@blu.org