Dan Hatton dan.hatton@btinternet.com writes:
I'm trying to run the command
sleepd --sleep-command "/usr/bin/apm -S" -u 900
to conserve some energy, by putting my computer in standby after 15 minute of idling. This command works fine when I type it at a tcsh or sh prompt, but now I want to run it at boot time.
The Debian booting structure is guiding me to do this via a distro-provided script, /etc/rc5.d/S20sleepd (a symlink to somewhere else, IIRC.) I've appended the full text of this script below, but I think the crucial bits are
#! /bin/sh
DAEMON=/usr/sbin/sleepd NAME=sleepd
PARAMS="" if [ -e /etc/default/sleepd ]; then . /etc/default/sleepd fi
case "$1" in start) start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \ --exec $DAEMON -- $PARAMS
The unquoted $PARAMS is being split into separate arguments _to start-stop-daemon_ on the whitespace it contains. There's nothing you can put in the value of PARAMS that will stop this. With this approach there is no way to write arguments that contain spaces as you need.
If you wrote "$PARAMS" then the internal spaces would be preserved, but you'd only be able to pass a single argument to start-stop-daemon (and thus to sleepd). Again there is nothing you can put in the value of PARAMS that will stop this.
In other words you can't easily write a fully general init script using an ordinary variable to carry the parameters (though evidently it hasn't stopped people trying).
You might be able to do something filthy using 'eval', but the reults would likely not be pretty.
My preferred approach would be to use the positional parameters to pass parameters to the daemon, for instance something like this untested(!) example:
#! /bin/sh set -e DAEMON="/usr/sbin/sleepd" NAME="sleepd" what="$1" set -- --sleep-command "/usr/bin/apm -S" -u 900 if [ -e /etc/default/sleepd ]; then . /etc/default/sleepd fi case "$what" in start ) start-stop-daemon --start --quiet --pidfile "/var/run/$NAME.pid" \ -exec "$DAEMON" -- "$@" ;; # ... etc etc etc ... esac
(Note that this would change the meaning of /etc/default/sleepd too.)