LinHES Forums http://forum.linhes.org/ |
|
UseChromaKeyOSD.sh script and mini SQL tutorial http://forum.linhes.org/viewtopic.php?f=3&t=16793 |
Page 1 of 1 |
Author: | tjc [ Sun Sep 30, 2007 11:38 am ] |
Post subject: | UseChromaKeyOSD.sh script and mini SQL tutorial |
Here is a little script which shows you how to do several things with mysql:
2) Insert a new record 3) Update an existing record 4) Delete an existing record Code: #!/bin/bash
# Script - UseChromaKeyOSD.sh usage () { cat 1>&2 <<EOF Usage: $0 on - or - $0 off EOF } if [ $(id -u) -ne 0 ] ; then echo "You must run this script as root!" exit 1 fi # SQL command strings select="select count(*) from settings where value='UseChromaKeyOSD' and hostname='$(hostname)'" delete="delete from settings where value='UseChromaKeyOSD' and hostname='$(hostname)'" # The mysql options used here get rid of all the output decoration and # leave just the answer. record_exists=$(mysql mythconverg -sBNe "$select") case "$*" in [Oo][Nn]|[Tt]rue|1) DATA="1" ;; [Oo][Ff][Ff]|[Ff]alse|0) DATA="0" ;; PURGE) # Undocumented "make them go away completely" option... [ "$record_exists" -ne 0 ] && mysql mythconverg -e "$delete" ;; *) usage exit 1 esac # More SQL command strings update="update settings set data='$DATA' where value='UseChromaKeyOSD' and hostname='$(hostname)'" insert="insert into settings set value='UseChromaKeyOSD', data='$DATA', hostname='$(hostname)'" if [ "$record_exists" -eq 0 ] ; then mysql mythconverg -e "$insert" else mysql mythconverg -e "$update" fi # Verify... mysql mythconverg -e "select * from settings where value='UseChromaKeyOSD'" |
Page 1 of 1 | All times are UTC - 6 hours |
Powered by phpBB® Forum Software © phpBB Group http://www.phpbb.com/ |