File: example_event_script

package info (click to toggle)
powersave 0.15.20-3
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 4,360 kB
  • ctags: 610
  • sloc: sh: 10,767; cpp: 5,264; ansic: 1,495; makefile: 342
file content (50 lines) | stat: -rwxr-xr-x 2,409 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash
#
# This is an example of a script to be put into
# /usr/lib/powersave/scripts/. Its name can then be used as an
# event name in /etc/sysconfig/powersave/events.
# Part of the powersave package.
#
# Stefan Seyfried, 2005
#
# First, we pull in the helper functions.
# This does the following:
# - expands PATH to the script path, sets the following variables:
#  SCRIPT_DIR    - the directory where the scripts are
#  EV_ID         - the event id, needed for SCRIPT_RETURN
#  SCRIPT_RETURN - the binary that tells powersaved that we finished
#  MYNAME        - the name of this script
#  LOGGER        - command to log something: '$LOGGER "custom script logging"'
#  SYSCONF_DIR   - where the config files are lying around
# - sources $SYSCONF_DIR/common for basic config variabes.
# - provides some funcions:
#  DEBUG     - for logging depending on the $DEBUG variable
#  EXIT      - for exiting the script. Don't exit via "exit"!
# - sets a trap on exit so that even syntax errors in your scripts or
#   unwanted codepaths or even foreign termination still lead to a controlled
#   feedback for the powersaved via SCRIPT_RETURN
#   This trap gets reset if you exit via the EXIT function - this is what it
#   is for :-)
. ${0%/*}/helper_functions # `dirname $0`/helper_functions

########################################################################
# put your own code here ###############################################
########################################################################

echo "i am a custom event script and pollute the syslog." | logger
$LOGGER "i can even do some more sophisticated logging"
DEBUG "and even depending on the DEBUG variable!" WARN

########################################################################
# this must be called to tell powersaved that processing of this
# event is finished. If your script is totally asynchronous, you
# can call this at the beginning of the script, before your code.
# in this case, powersaved will *not* wait for your script to finish.
# if you do not call this, weird things will happen.
########################################################################
$SCRIPT_RETURN $EV_ID 0 "my_custom_event_script finished"

########################################################################
# reset the trap and exit with status 0
########################################################################
EXIT 0