[ncolug] Re: Linux Home Automation


Rob Gibson <nosbig@xxxxxxxxx> wrote: Here is the next revision...  What do you 
all think?

#!/bin/bash

# Initialize command substitutions
LS=/bin/ls
WC=/usr/bin/wc
PING=/bin/ping
ECHO=/bin/echo
BR=/usr/bin/br
SLEEP=/bin/sleep
RM=/bin/rm
DATE=/bin/date
MKTEMP=/bin/mktemp
FIND=/usr/bin/find

# Initialize Paths and Ports
LOGFILE=/var/log/x10.log
TMPPATH=/var/tmp/x10
TEMPLATE=failure
X10PORT=/dev/ttyS0
X10DEVICE=G15

${PING} -c 5 www.google.com &> /dev/null || ${MKTEMP} -p ${TMPPATH}
${TEMPLATE}XXXXXXXXXX &> /dev/null
if [ $(${FIND} ${TMPPATH} -type f -name "${TEMPLATE}*" -print | ${WC}
-l) -gt 2 ]
###if [ $(${LS} -1 ${TMPPATH}/${TEMPLATE}* | ${WC} -l) -gt 2 ]
then
        ${BR} -x ${X10PORT} ${X10DEVICE} OFF
        ${SLEEP} 5
        ${BR} -x ${X10PORT} ${X10DEVICE} ON
        for file in $(${FIND} ${TMPPATH} -type f -name "${TEMPLATE}*" -print)
        do
                ${RM} ${file}
        done
        ${ECHO} -ne "Network Failure: " >> ${LOGFILE}
        ${ECHO} $(${DATE} +"%Y-%m-%d-%M%S") >> ${LOGFILE}
fi

On Dec 15, 2007 11:35 PM, Mike  wrote:
> Rob Gibson wrote:
> > Since Mike raised the issue, why is it bad to use a ~/bin directory?
> > This script is a bad example, as the actions of this script inherently
> > affect all users of the system.  In production use (and my next
> > revision), I would put the script in /usr/local/bin.  But, I have
> > several scripts which are just short one-line scripts for recalling
> > some of my personal internet radio streams.  For those items which are
> > designed by one user for that user to only, would it not make sense to
> > place the files in the user's home directory?  Or did I miss a chapter
> > of the FHS or something?  ;-)
> >
>
> Short one liners are great in ~/bin, that is one place to put them.
> Often I create ~/temp.d or ~/tmp.d and put stuff there.  Those aren't in
> my path so must be called appropriately.  No this isn't a violation of
> FHS to my knowledge, just be warned that on a multiple user system it
> will cause you headaches.  Chuck offered to comment in another post if
> there was interest.  I still will defer all further to him, too many
> nightmares!
>
> > The new revision will include mktemp directories and placing them in
> > /var/tmp.  I like the idea of having all of the files located in a
> > designated temp directory.  The output is definitely something I would
> > keep.  I just don't want cron reporting the success output of 5 pings
> > every 5 minutes...  ;-)  So, I dumped that output.  If anything else
> > goes wrong, I will get the message.
> >
>
> Guess I might not have gotten my point across here.  Cron by default
> will email you _any_ output that a script generates, not just errors.
> If this info isn't useful most people start treating it like spam and
> start to ignore it.
>
> > The serial device permissions, I am not worried about.  The perms on
> > /dev/ttyS0 are 660 with root:dialout.  My user belongs to the dialout
> > group.  Since no dial-up modems are in use here and never will be on
> > this device, I might remove all users from dialout, add nobody to that
> > group, and run the script from nobody's crontab.
> >
> > Rob
>
> The dialout group is probably just a legacy name nowadays.  My point was
> probably missed here also.  Say in the current version someone did get
> control via a race condition or some other method.  When they got a
> shell or the ability to execute an overwritten file, they now have
> access to the serial port as you, also then control of your X10 devices.
>   Likely to happen?  Probably not a high risk, still worthy of
> consideration in my mind.  Actually I'd be more concerned that the race
> condition existed to begin with.
>
>
> Mike
>
> nice work, Rob, i see where there revisions were placed
is the file kept in /usr/local/bin ?

       
---------------------------------
Looking for last minute shopping deals?  Find them fast with Yahoo! Search.

Other related posts: