View unanswered posts    View active topics

All times are UTC - 6 hours





Post new topic Reply to topic  [ 1 post ] 
Print view Previous topic   Next topic  
Author Message
Search for:
PostPosted: Sun Sep 30, 2007 11:38 am 
Offline
Joined: Thu Mar 25, 2004 11:00 am
Posts: 9551
Location: Arlington, MA
Here is a little script which shows you how to do several things with mysql:
    1) Check for a records existence
    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'"


Top
 Profile  
 

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 


All times are UTC - 6 hours




Who is online

Users browsing this forum: No registered users and 14 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group

Theme Created By ceyhansuyu