On 07/05/10 11:52, Ian Abbott wrote:
On 05/07/10 09:40, [email protected] wrote:
I have a trivial script to set and env var and export it .
DELAY=16
cat /usr/local/bin/cron_delay.sh
#!/bin/sh
# work around challenged crontabs
# set env var for cronjob
export DELAY=15
/usr/local/bin/cron_delay.sh
echo $DELAY
16
/bin/sh
BusyBox v1.17.0.git (2010-05-27 20:35:42 CEST) built-in shell (ash)
Enter 'help' for a list of built-in commands.
Why does export not work ?
Because you can't modify the parent process's environment variables.
When you run /usr/local/bin/cron_delay.sh, you are creating a new
process which executes /bin/sh (with the pathname of the script as its
first argument). That new process can modify it's own environment
variables and pass them on to processes it creates, but it can't modify
the environment of its parent process. This is a standard unix feature,
not a bug.
It's possible to run the script within the current shell process
(instead of spawning a new process) using the "source" or "." built-in
shell command:
source /usr/local/bin/cron_delay.sh
Since it's the current shell process that's running the commands in the
script, any changes to environment variables will be in the current
shell process, and will be passed on to any other processes created by
the current shell process.
Ian, thanks for taking the time to explain so thoroughly my stupid
mistake.
However, it is not working using source. I reduced my cron job to simply
sourcing that script it fails to get called. Seeing no output form crond
generally indicates an error in crontab.
I tried su to the relevent account and ran crontab -l.
$ crontab -l
crontab: must be suid to work properly
I have noted the warning that suggests busybox may need to be suid but
hesitate since having just about any and all shell commands running suid
makes me a bit twitchy. Until now this has never produced an issue in
what I use this system for.
The rest of my cron jobs work as required.
Is this a red herring or does suidhave some bearing on why I cannot
source the script?
There are certainly other ways to get around what I need to do what I
need but I don't like walking away from a problem just because I don't
understand what is happening.
This seems like an awful lot of effort and problems just to set an env var !
01,16,31,46,25 * * * * source /usr/local/bin/cron_delay.sh
:?
Thanks for your help.
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox