beta 296.1

7 replies [Last post]
brett
Offline
Providence, United States
Joined: 9 Jan 2010

The following changes have been made to a beta 296.1
* cron/crontab have been installed in the busybox
* I removed a number of useless busybox commands (saves flash)
* Start only 1 kloned prefork child (saves memory)

To update to the beta

# /etc_ro_fs/update-dev hah-beta.dbzoo.com

To get cron working after upgrading to the beta you need to do the following
# ln -s /etc_ro_fs/init.d/cron /etc/init.d/cron
# ln -s /etc_ro_fs/rc1.d/S41crond /etc/rc1.d/S41crond

To get cron running you can either reboot or start it manually.
# /etc/init.d/cron start

http://adminschoice.com/crontab-quick-reference
crontab -e    Edit your crontab file, or create one if it doesnt already exist.
crontab -l      Display your crontab file.
crontab -r      Remove your crontab file.

I plan that these would probably just make calls to scripts that would send xAP events.

So something like this would turn on a light at 9am every Monday and off again the same day at 5pm.

* 9 * * 1 lua /etc/cron/turnonlight.lua
* 17 * * 1 lua /etc/cron/turnofflight.lua

The LUA scripts would be as simple as

require("xap")
xap.sendShort(string.format[[
insert xap-payload here
]])

Just thoughts and some progress on getting a local scheduler working.

Brett

brett
Offline
Providence, United States
Joined: 9 Jan 2010
Scripting with the scheduler

So here is some food for thought we can create scripts that allow some level of BSC control and their behaviour can be adjusted using parameters.  This make a nice neat control interface.

We will create a scripts call "bsc" and put this in the /etc/cron directory - don't forget to chmod a+x this!

#!/usr/bin/lua

local args = require("pl.lapp") [[
  Various flags and option types
    -t (string)      xAPBSC Target
    -s (default on)  xAPBSC State
    -x               xAPBSC Text
]]
require("xap")

if args.t == false then
  print("Missing target")
  os.exit()
end

xap.init("dbzoo.livebox.cron","FF123400")
cmd = string.format([[
xap-header
{
class=xAPBSC.cmd
target=%s
}
output.state.1
{
id=*
]],args.t)

if args.s then
  cmd = cmd .. "state="..args.s .. "\n"
else
  cmd = cmd .. "state=on\n"
end

if args.x then
  cmd = cmd .. "text="..args.x.."\n"
end
cmd = cmd .. "}"

xap.sendShort(cmd)

 

NOW back to the crontab to crontrol some lights connected via the crontab we can do this

0 17 * * * /etc/cron/bsc -t dbzoo.livebox.controller:relay.1 -s on
0 21 * * * /etc/cron/bsc -t dbzoo.livebox.controller:relay.1 -s off

This will turn the lights on at 5pm every day and then off again at 9pm.

Again this is just me thinking out loud pipe up if you have other ideas but this is shaping up to be pretty flexible in my opinion. Albiet you need to write some code but hey that is what make is flexible.  I'll work on some nice control scripts I can supply in my next beta drop.

Brett

edit: fixed crontab entry I had them turning on at 17min past the hour and off again at 21min past.  Fine if you want disco lights to attract Santa.

brett
Offline
Providence, United States
Joined: 9 Jan 2010
want your computer ready for you in the mornings?

So I was thinking about crontab and the fact that I always sleep my computer when I'm done for the day.  With this entry on the HAH I can use the Wake-on-lan facility to make sure my work machine is always ready for me at 7am monday-friday.  note: requires beta 296.1 and cron setup.

# crontab -l
0 7 * * 1-5 ether-wake -i br0 3c:d9:2b:5b:67:c2
#

I'll let you know tomorrow if that worked :)

BoxingOrange
Offline
United Kingdom
Joined: 11 Jun 2010
Scheduled Backup

Here's a first stab at writing a script to use with the new cron functionality that will backup some files.

Create a file in /etc/cron and paste this into it, ie /etc/cron/hahbackup :-

 

#Create a backup file called /tmp/hahbackup.tar.gz
cd /
tar cvf - /etc/xap-livebox.ini /etc/passwd /etc/plugboard /etc/cron | gzip -9c > /tmp/hahbackup.tar.gz

Then chmod a+x /etc/cron/hahbackup, this makes it executable.

 

Edit your crontab, crontab -e, to run the script every day at 1am, * 1 * * 0-6 /etc/cron/hahbackup

To get all of the files out type :-

cd /
gunzip /tmp/hahbackup.tar.gz
tar xvf /tmp/hahbackup.tar

Or to get individual files :-

cd /
gunzip /tmp/hahbackup.tar.gz
tar xvf /tmp/hahbackup.tar <filename>

i.e. to restore your /etc/xap-livebox.ini file

cd /
gunzip /tmp/hahbackup.tar.gz
tar xvf /tmp/hahbackup.tar etc/xap-livebox.ini

Hope this helps, It's almost what Dean asked for in another post, you can obviously add any files that you think are important, and I'm sure Brett will have some constructive criticism.  Remember to keep the backup file somewhere safe.
brett
Offline
Providence, United States
Joined: 9 Jan 2010
That is a lot of backing up!

I'm afraid your crontab entry will run the backup every 1 minute from the hours 1am to 1:59am.

* 1 * * 0-6 /etc/cron/hahbackup

You need to use this

0 1 * * * /etc/cron/hahbackup

Brett

BoxingOrange
Offline
United Kingdom
Joined: 11 Jun 2010
I knew there'd be something,

I knew there'd be something, I was thinking wrong place to store the backup file or something like that though.  

brett
Offline
Providence, United States
Joined: 9 Jan 2010
Getting pedantic

Well if you want to get pedantic I can find more

cd /
gunzip /tmp/hahbackup.tar.gz
tar xvf /tmp/hahbackup.tar

All this can be done in one line and you don't have to uncompress to a temporary file first.

cd / && gzip -dc /tmp/hahbackup.tar.gz | tar -xvf -

I didnt test this.

BoxingOrange
Offline
United Kingdom
Joined: 11 Jun 2010
That's great thanks, I'll

That's great thanks, I'll give it a go.  Just using your e-mail script to get the HAH to send an e-mail when it's done :)

Hardware Info