Persist variables to file (~/.whenjobs/variables).
[whenjobs.git] / tools / tutorial.ml
1 (* whenjobs daemon
2  * Copyright (C) 2012 Red Hat Inc.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  *)
18
19 let tutorial = "\
20 (* Everything in (* ... *) is a comment.
21    Everything in << ... >> is a shell script.  Use >\\> to escape >> in script.
22
23    This is just a quick start.  For full documentation read the
24    whenjobs(1) man page by typing 'man 1 whenjobs'
25
26    Use 'every <period> : << >>' to run a shell script periodically
27    (like cron).  Don't forget the colon!
28
29 every 10 minutes :
30 <<
31   # Get free blocks in /home
32   free=`stat -f -c %b /home`
33   # Set the variable 'free_space'
34   whenjobs --set --type int free_space=$free
35 >>
36
37    Use 'when <expr> : << >>' runs the shell script only when
38    the expression is true.  'changes' is a function that monitors
39    a variable and returns true when it changes value.
40
41 when changes free_space && free_space < 100000 :
42 <<
43   mail -s \"ALERT: only $free_space blocks left on /home\" $LOGNAME </dev/null
44 >>
45
46 *)
47 "