LinHES Forums
http://forum.linhes.org/

Making ver.sh more usefull
http://forum.linhes.org/viewtopic.php?f=3&t=18450
Page 1 of 1

Author:  mjl [ Thu Jul 03, 2008 5:54 am ]
Post subject:  Making ver.sh more usefull

Hi,
I don't know if this is really the right place to put this but I find this little tweak I do quite handy.

As far as I can see the current "version" is about useless for the general world. It gives information that would only be used to for working on a problem. I work on a lot of problems, but my short term memory sort of sucks a little so I use "version" to help me along the way.

I do several things to Cecil's original ver.sh so that It will help me when I need a memory prompt.

First, I add two lines to /usr/local/bin/mythbackup

#!/bin/bash
echo -n "Last Backup was on ">/home/mythtv/lbu.txt
date >>/home/mythtv/lbu.txt

Then I add a line to /etc/X11/fluxbox/keys
echo "Mod1 v :ExecCommand ver.sh" >>/etc/X11/fluxbox/keys

Put in an entry into mythtv crontab
# Daily Drive space checkup
0 20 * * * sh /usr/bin/run-space-check.sh &>/dev/null

And add a modified (original was posted on forum somewhere) script called /usr/bin/run-space-check.sh

Code:
#!/bin/sh
# Drive space warning script
#-------------------------------------------------------------
lsmod |grep "ivtvfb "|cut -b1-6 >/tmp/tv
if [ "$(cat /tmp/tv)" = "ivtvfb" ]; then
fontsize="25"
fontcolor="lightyellow"
else
fontsize="34"
fontcolor="yellow"
fi
export DISPLAY=:0
export FONT="-adobe-helvetica-bold-*-*-*-$fontsize-*-*-*-*-*-*-*"
#----------------------------------------------------------------
email=0                    # 1 or greater to enable email
show=1                     # 1 to show osd
echo -n "" > /tmp/tts             # Nice to know when things happen
ALERT_PERCENTAGE=75        # 90% disk used, ~500mb remaining on stock install?
HOSTNAME=`hostname`
RREMAINING=`df / |awk '{print $5}' |tail -1 |sed s/%//`     # root status
MREMAINING=`df /myth |awk '{print $5}' |tail -1 |sed s/%//` # myth status

# root
echo " Root Partition has used ${RREMAINING}% of space." >>/tmp/tts
if [ $ALERT_PERCENTAGE -lt $RREMAINING ]; then
        date > /tmp/tts
        echo "WARNING, $HOSTNAME has ${RREMAINING}% root disk space used." >>/tmp/tts
        # bump flag
        email="$(($email + 1 ))"
        show="$(($show + 1 ))"
fi

ALERT_PERCENTAGE=85        # 85% myth partition used
REMAINING=`df /myth |awk '{print $5}' |tail -1 |sed s/%//`
# myth
echo " Myth Partition has used ${MREMAINING}% of space." >>/tmp/tts
if [ $ALERT_PERCENTAGE -lt $MREMAINING ]; then
        date > /tmp/tts
        echo "WARNING, $HOSTNAME has ${MREMAINING}%  disk space used for media." >>/tmp/tts
        # bump flag
        #email="$(($email + 1 ))"
        #show="$(($show + 1 ))"
fi

# show it from here if flagged
if [ $show -gt "1" ]; then
        cat /tmp/tts | osd_cat --l=8 --delay=6 --font=$FONT --shadow=3 --color=$ fontcolor  --pos=bottom --align=centre &
fi

# email it from here if flagged
if [ $email -gt "1" ]; then
#       Email me when root disk usage exceeds a specified percentage.
        date > /tmp/tts
        SENDER=mythtv@my.house
        RECIPIENT=emailme@my.work
        SMTP_SERVER=mail.my.isp
        df -h | sendEmail -f $SENDER -t $RECIPIENT -s $SMTP_SERVER -u "$HOSTNAME  has ${RREMAINING}% root disk space used."
        email=0
fi

#done


Finally, I beat up on Cecil's original /usr/local/bin/ver.sh script to make it useful to me.

Code:
#!/bin/bash
killall osd_cat
lsmod |grep "ivtvfb "|cut -b1-6 >/tmp/tv
if [ "$(cat /tmp/tv)" = "ivtvfb" ]; then
fontsize="25"
fontcolor="lightyellow"
else
fontsize="34"
fontcolor="yellow"
fi
export FONT="-adobe-helvetica-bold-*-*-*-$fontsize-*-*-*-*-*-*-*"
export DISPLAY=:0
cat /etc/KnoppMyth-version > /tmp/ver
date >> /tmp/ver
echo "....." >> /tmp/ver
/sbin/ifconfig |grep eth |cut -b1-4 >/tmp/net
/sbin/ifconfig "$(cat /tmp/net)" | sed -n -e '/inet addr:\([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\).*/s//\1/p' | cut -c11-26 >/tmp/ip
echo -n  "IP $(cat /tmp/ip) _._ MythTV  - " >> /tmp/ver
cat /etc/hostname >> /tmp/ver
echo "....." >> /tmp/ver
cat /etc/mythtv/version >> /tmp/ver
echo "....." >> /tmp/ver
/usr/bin/run-space-check.sh
cat /tmp/tts >> /tmp/ver
cat /home/mythtv/lbu.txt >> /tmp/ver
cat /tmp/ver | osd_cat --l=14 --delay=18 --font=$FONT --shadow=2 --color=$fontcolor --pos=middle --align=centre&


Now when I press alt v or select version on the menu, I get some meat & potatoes. Those with a 350 card will see if the ivtvfb is loaded as the font changes color and size to work with a tv out display.

One cavet, ip will be blank if you have two nics, you will have to manually select one or the other. ( l left room for improvments Smile ) Caution if doing copy and paste, watch for line wrapped lines!

Many thanks to tjc & Human who made it possible for me to offer this.small token Smile
Mike

Author:  warchildx [ Thu Jul 03, 2008 8:29 am ]
Post subject: 

quick though. what format do you want the ip's listed as?

if you replace the following:
Code:
/sbin/ifconfig |grep eth |cut -b1-4 >/tmp/net
/sbin/ifconfig "$(cat /tmp/net)" | sed -n -e '/inet addr:\([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\).*/s//\1/p' | cut -c11-26 >/tmp/ip
echo -n  "IP $(cat /tmp/ip) _._ MythTV  - " >> /tmp/ver


with:
Code:
echo -n "IP(s) for Mythtv - " >> /tmp/ver
echo "" >> /tmp/ver
echo -n "$(/sbin/ifconfig |sed -n -e '/inet addr:\([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\).*/s//\1/p' |cut -c11-26)" >> /tmp/ver
echo "" >> /tmp/ver

you should wind up with something like this:

Code:
IP(s) for Mythtv -
172.16.2.63
1.2.3.4
127.0.0.1


Also, you dont have to create temp files for ip and net.

by the way, the this also handles multiple network cards. IF I run the original script on my box, instead of only getting the ip for eth0, I get nothing due to the script bombing out trying to ifconfig "eth0 eth1" or something similar.

Author:  warchildx [ Thu Jul 03, 2008 8:32 am ]
Post subject: 

PS: good work though, and I love the idea of having more information available onscreen.

Author:  mjl [ Wed Jul 09, 2008 9:18 pm ]
Post subject: 

Hi,

Thanks for the tips :) Not quite what I am after yet but does give me something to play with later on. Don't have the need for the lo ip to be displayed.

For those boy scouts, the _._ MythTV should have a meaning.

I did notice that I left out some other tid-bits that make for the rest of the information.
In the /usr/local/bin/mythbackup script, I add :
#!/bin/bash
echo -n "Last Backup run "> /home/mythtv/lbu.txt
date >> /home/mythtv/lbu.txt

#----------------------------------------------------------------------------

That is for the those like myself that don't remember when the last backup was started :)

And to compensate for the extra information, increase the line count to be ~ 18 in stead of 14
cat /tmp/ver | osd_cat --l=18 --delay=18 --font=$FONT --shadow=2 --color=$fontcolor --pos=middle --align=centre&

If and when I find the original space script I will also post the link so there is proper credits :)

It may not be pretty, but does work well enough for my needs.
Thanks
Mike

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/