Of the various TiVo hacks that people run, cron seems to cause the most queries, and so I wrote up the following TiVo cron mini-HowTo, if you find it of use or spot any errors then please email me
1 - Download cron-3.0pl1_TiVo-2.tar.gz from ftp://ftp.dtype.org/pub/tivo/dtype/
2 - ftp it to tivo:/var/hack
3 - Download http://www.lampy.demon.co.uk/tar.bin
4 - ftp it to tivo:/var/hack/bin
5 - telnet tivo, and do the following commands (the $ is a prompt character,
dont't type it :) )
$ cd /var/hack/bin $ mv tar.bin tar $ chmod +x tar $ cd .. $ gzip -dc cron-3.0pl1_TiVo-2.tar.gz | /var/hack/bin/tar -xvf - $ cd cron-3.0pl1_TiVo-2 $ chmod 755 cron $ sh ./cron-setup-tivo.sh $ mv cron ../bin $ mv crontab /var/hack/etc/crontab $ cd /var/hack $ rm -rf cron-3.0pl1_TiVo-2 $ /var/hack/bin/cron &
After this stage you should end up with files and directories with names and permissions listed as follows. The file dates may vary from the ones that are listed below, but assuming you grabbed the same cron tarball then the file sizes should be the same for /var/hack/bin/cron.
-rwxr-xr-x 131312 Jul 30 2002 /var/hack/bin/cron -rw-r--r-- 1513 Dec 30 12:21 /var/hack/etc/crontab drwxr-xr-x 1024 Oct 15 09:52 /var/hack/etc/cron.d drwxr-xr-x 1024 Oct 15 10:07 /var/hack/cron -rw-r--r-- 4 Dec 30 20:38 /var/hack/cron/cron.pid -rw------- 18852 Jan 2 07:20 /var/hack/cron/log drwx------ 1024 Oct 15 10:07 /var/hack/cron/tabs
Add "/var/hack/bin/cron &" to /etc/rc.d/rc.sysinit.author, and edit your /var/hack/etc/crontab as required.
If things don't work and you need to debug them then you'll need the ps binary
from http://www.xse.com/leres/tivo/downloads/ps and
the ls binary from the tarball at http://tivo.stevejenkins.com/downloads/tivobin.tgz.
If you haven't already installed these then see my TiVo installation diary here for
a walkthrough of their installation.
The first thing to test out is cron itself, I normally do this by editing the /var/hack/etc/crontab either via the elvis binary (again see here for installation instructions for elvis) or via the Tivo Web HackManager tool. If you add an entry to /var/hack/etc/crontab file which looks like this
*/10 * * * * date >> /var/hack/cron.test.out
then every 10 minutes cron should write the current date into the /var/hack/cron.test.out file. There is an entry in crontab by default which does this, but its commented out, so just remove the leading # if this is the case.
Then, after making the changes, restart cron by doing
$ ps auxLook for the process ID of the cron process, e.g. example output from the above is
root 401 0.0 1.2 1140 172 ? S Dec 30 0:00 /var/hack/bin/cron
and so the process ID is the number in the second field, i.e. 401 in this particular case.
If you didn't install the ps binary mentioned above, then as an alternative you can do
$ tivosh % ps aux
In which case the process ID is the first field in the cron line, e.g. the output from the above is
401 1 S 0 27 /var/hack/bin/cron
$ kill -9 <the_process_id>and then restart cron via
$ /var/hack/bin/cron &
To test a cron-enabled tool, for example DailyMail, there are two areas to test. Firstly, does the tool work ok when run from the command line, and secondly does it work when run from cron. With DailyMail for example, just run the dailymail.tcl script from the command line and see if it works ok.
If the tool doesn't appear to be running at all from cron, then firstly check that cron is finding it. In general (this depends on how you invoked it but...) cron does NOT inherit the PATH list that you have specified in your .login profile, it runs with the PATH variable that is in existence when rc.sysinit.author launches cron. This means that if you have sometool located in /var/hack/bin, then cron won't find it if you code the crontab entry as
mm hh dd mm yy sometooleven though you can type "sometool" at the command line. Instead you'll need to code the full path within the crontab entry, i.e.
mm hh dd mm yy /var/hack/bin/sometool.
If things still aren't working then..
If you've checked that the tool works from the command line, and tried specfifying the full pathname in the crontab entry, and cron still doesn't run the tool then cron does have some debug modes which can be of help.
To use them, kill off the running background cron process (see earlier for instructions on how to do this) and do
$ /var/hack/bin/cron -x pars
This should produce output something like this...
debug flags enabled: pars [1294] cron started load_user() load_env, read <SHELL=/bin/sh> load_env, <SHELL> </bin/sh> -> <SHELL=/bin/sh> load_env, read <PATH=/sbin:/bin:/usr/sbin:/usr/bin:/var/hack/bin> load_env, <PATH> </sbin:/bin:/usr/sbin:/usr/bin:/var/hack/bin> -> <PATH=/sbin:/bin:/usr/sbin:/usr/bin:/var/hack/bin> load_env, read <MFS_DEVICE=/dev/hda10> load_env, <MFS_DEVICE> </dev/hda10> -> <MFS_DEVICE=/dev/hda10> load_env, read <TIVO_ROOT=""> load_env, <TIVO_ROOT> <> -> <TIVO_ROOT=> load_env, read <15 7 * 1-3,10-12 * /var/hack/scripts/summerzone.sh && /var/hack/dailymail.tcl >/var/hack/dailymail.out 2>/var/hack/dailymail.err &> load_env, not 2 fields (1) load_entry()...about to eat comments load_entry()...about to parse numerics load_entry()...about to parse command load_entry()...returning successfully
The process numbers, and crontab lines will differ depending on what you coded into your crontab. But the key thing is that for each crontab entry which you put in your /var/hack/etc/crontab, you should see a "load_env, read" ... "load_entry() ... about to parse command" ... "load_entry()...returning successfully" set of output lines.
If when you do the "/var/hack/bin/cron -x pars" command you get the following :-
/var/hack/bin/cron: can't lock /var/hack/cron/cron.pid, otherpid may be <a_numeric>: Resource temporarily unavailable log_it: (CRON <a_numeric>) DEATH (can't lock /var/hack/cron/cron.pid, otherpid may be <a_numeric>: Resource temporarily unavailable)
then it means that you still have the background cron process running and didn't kill it off completely, so kill it off and retry the command.
If you see the crontab file being successfully parsed, then do a Control-C to terminate the cron process and then do a
$ /var/hack/bin/cron -x ext,sch,proc
This should show you output along the lines of
debug flags enabled: ext sch proc [1297] cron started [1297] TargetTime=1105121160, sec-to-wait=19 [1297] sleeping for 19 seconds [1297] tick(6,18,6,0,5) user [cron:0:0:...] cmd="/var/hack/scripts/summerzone.sh || /var/hack/dailymail_jazz.sh &" user [cron:0:0:...] cmd="/var/hack/scripts/summerzone.sh && /var/hack/dailymail_jazz.sh &" user [cron:0:0:...] cmd="/var/hack/scripts/summerzone.sh || date >/var/hack/dailymail-run &" user [cron:0:0:...] cmd="/var/hack/scripts/summerzone.sh && date >/var/hack/dailymail-run &" user [cron:0:0:...] cmd="/var/hack/scripts/summerzone.sh || /var/hack/dailymail.tcl >/var/hack/dailymail.out 2>/var/hack/dailymail.err &" user [cron:0:0:...] cmd="/var/hack/scripts/summerzone.sh && /var/hack/dailymail.tcl >/var/hack/dailymail.out 2>/var/hack/dailymail.err &" [1297] TargetTime=1105121220, sec-to-wait=60 [1297] sleeping for 60 seconds
until its time to launch a cron entry. If you Control-C, then force a cron task to be launched by updating the crontab file and setting the timestamp on an entry to (now + 1 minute), then re-do the cron command then you should see a task launched.
For example, if it was 18:06 and I updated my crontab entry to add
08 18 * * * * date >/tmp/blah
and then saved the change and re-did the "crontab -x ext,sch,proc" command then I would see during the parsing section
user [cron:0:0:...] cmd="* date >>/tmp/blah"and at the appointed time I would see
[1300] TargetTime=1105121340, sec-to-wait=60 [1300] do_command(* date >>/tmp/blah, (*system*,0,0)) [1300] main process returning to work [1300] TargetTime=1105121340, sec-to-wait=60 [1300] sleeping for 60 seconds [1301] child_process('* date >>/tmp/blah') [1301] child continues, closing pipes [1301] child reading output from grandchild [1302] grandchild process Vfork()'ed log_it: (cron 1302) CMD (* date >>/tmp/blah) [1301] got data (2f:/) from grandchild [1301] closing pipe to mail [1300] sigchld...pid #1301 died, stat=0 [1300] sigchld...no children [1300] sleeping for 59 seconds [1300] tick(9,18,6,0,5)
this cron entry was successfully launched, and completed without errors. However if you are seeing errors from the forked process then hopefully the error messages should give you some areas to focus your attention on.
Once you've found the source of your problem then you can Control-C any running debug-enabled cron, and then do
$ /var/hack/bin/cron &
to re-launch cron in the background.
I've noticed that when logging out of my TiVo after starting commands off in the background then the logout completes but the telnet session isn't always closed off. I just kill the telnet window manually in those cases.
The format of crontab lines is as follows, each entry is a 6 field space-seperated line where the fields are :-
5 * * * * echo 'Hello'
"Minute" is the minute value, i.e. 0 to 59
"Hour"
is the 24-hour clock hour value, i.e. 0 to 23
"MDay" is the day of the month, i.e. 1 to 31
"Month" is the numeric month value, i.e. 1 to 12 for January through December.
You can also use the textual abbreviated names jan..dec
"DayOfWeek" is the Unix "Day of Week" number, this is 0 through 6 for Sunday
through Saturday.
i.e. 0=Sunday, 1=Monday, ... 6=Saturday.
You can also use the textual abbreviated
names sun..sat
"Command" is the command to be run, any valid command-line.
There are various special characters which you can use within the fields.
An asterisk in any field means "match any value", e.g. every day or every month.
Commas in any field means that multiple values are specified, e.g. in the "Day
of Week" field 1,3,5 would mean Monday,Wednesday,and Friday.
Dashes specify ranges, e.g. 9-17 in the hours field would mean every hour between
9am
and
5pm inclusive.
A forward slash means a repeating event, e.g. */10 in the minutes field would
mean
every
10
minutes.
Examples
* * * * * /var/hack/somecommand - Execute "/var/hack/somecommand" every minute
of every hour of every day
45 7,19 * * mon-fri /var/hack/somecommand - Execute "/var/hack/somecommand" at
7:45am and 7:45pm Monday-Friday
30 2 1-10 * * /var/hack/somecommand - Execute "/var/hack/somecommand" at 2:30am
on the first to the tenth of every month
Most people are probably installing cron in order to run dailymail (or dailymail_jazz nowadays). To do this, firstly install dailymail_jazz :-
- Download dailymail_jazz from http://www.tivocommunity.com/tivo-vb/showthread.php?s=&threadid=140252&perpage=20&pagenumber=59 or http://www.deepinthejungle.com/Tivo/Tivoindex.htm
- Unpack the zip file onto a PC
- ftp dailymail/dailymail.cfg to tivo:/var/hack/
- ftp dailymail/dailymail_jazz.tcl to tivo:/var/hack/
- ftp tivoweb-modules/controlpadding.itcl to tivo:/var/hack/tivoweb-tcl/modules/
(only needed if you are using EndPad)
- ftp tivoweb-modules/managedailymail.itcl to tivo:/var/hack/tivoweb-tcl/modules/
- On your web server, mkdir <apache_root>/htdocs/tivo/dailymail_jazz.
- On your PC, transfer images/* to your web server:<apache_root>/htdocs/tivo/dailymail_jazz/
- On the TiVo, elvis /var/hack/dailymail.cfg
Change...
set mailserver "<your_smtp_server_ip>"
set domain "<your_domain">
set receipient "<your_email>"
set version3 false
set uktivo true
set endpadinstalled false (or true if you use endpad)
set reddotinstalled false (or true
if you use endpad)
set tivowebplususer false (or true
if you use tivoweb plus)
set dmailHoursahead 48
set dmailShowSuggestions true
set mailcheckingon true
set dmailLinksOn true
set graphicson true
set endpadstatus false
set reddotstatus false
set spacebarrequired true
set emailsendrequired true
set htmlfilerequired true
set yankspeak false
set dmailTivoURL "http://your_tivos_hostname_or_ip"
set dmailGraphicsURL "http://your_webservers_hostname/tivo/dailymail_jazz/"
$ chmod +x dailymail_jazz.tcl
- Do a TivoWeb full restart
- You should now be able to type "/var/hack/dailymail_jazz.tcl" on
the command line, and all being well you'll receive your dailymail_jazz email
shortly afterwards.
Next, cron-enable dailymail_jazz.
To do this, you can run the dailymail_jazz.tcl script directly from cron, but some people find that their TiVo reboots due to memory pool shortage. To work around this, I created a dailymail_jazz wrapper script which increases the memory pool size and then runs dailymail_jazz. In order to do this :-
$ cat >>/var/hack/dailymail_jazz.sh
#!/bin/sh export TIVOSH_POOLSIZE=3244032 /var/hack/dailymail_jazz.tcl > /var/hack/dailymail_jazz.out 2>&1<Ctrl-D>
$ chmod +x /var/hack/dailymail_jazz.sh
- Add to /var/hack/etc/crontab
20 6 * * * /var/hack/dailymail_jazz.sh &
to have dailymail run at 06:20 every day.
- Restart cron.
For some reason the other night tnlited fell over in the small hours and so I couldn't telnet into my TiVo next morning. TivoWeb wasn't running (and I didn't have HackMan installed anyway) so I couldn't restart it that way, and I was 300 miles away from home so I couldn't reset it from the UI.
ftp and cron were still running though, so what I did to restart a telnet service was to grab the current crontab via ftp at 12:15 BST, and add
20 11 * * * /sbin/tnlited 24 /bin/bash 20 12 * * * /sbin/tnlited 25 /bin/bash
to the crontab, then ftp it back. Then I waited until 12:20 BST and telnetted back into the TiVo on port 24. That gave me a shell, I then relaunched tnlited with its proper run command, and and started up tivoweb again (and removed the temporary tnliteds from the crontab).
The reason I put two tnliteds in the crontab an hour apart was because I couldn't remember if the effective timezone for cron was GMT or BST.