hello,
I've a problem runnnig beforeshutdown.sh, need some advice I guess.
The script in /home/pi/wittipi/beforeshutdown.sh is quite simpe, for testing purposes:
echo $(date) >> /home/pi/log.txt sleep 5
But it's not executed, as far as a I can see, no matter if I put it directly into beforeshutdown.sh or in an extra script file. There is also no hint or error in the logs. I want to record some info when low voltage threshold is hit or on scheduled shutdowns, and thought beforeshutdown.sh is the right place for that.
(raspberry pi zero, wittyipi 3 mini)
thanks for help, uno
You need to use absolute path of the command. Because the daemon.sh is run by the root user, so is the beforeShutdown.sh script.
You can use "which" command to find out the absolute path of the command, for example:
which each
/usr/bin/echo
which sleep
/usr/bin/sleep
Your script content should be updated to:
/usr/bin/echo $(date) >> /home/pi/log.txt /usr/bin/sleep 5
well, yes. It seems that "beforeShutdown.sh" ist executed with no PATH info, so it does not find any executables in the system. Guess that should be mentionend in the docs...
I've added the following to beforeShutdown.sh:
PATH="home/pi/bin:/usr/sbin:/usr/bin:/sbin:/bin" export PATH
I think that's more suitable in case a custom script calls more that a few commands.
u.
Guess that should be mentionend in the docs...
It is mentioned in Witty Pi 4 Mini's document, on page 31~32.
In Witty Pi 4's software, the beforeShutdown.sh file also contains this comment:
# Remarks: please use absolute path of the command, or it can not be found (by root user).
Witty Pi 3 Mini has been discontinued since July 2022, and its document and software have not been updated since then.
sorry, missed that, thanks for the hint!
just curious, why don't you recommend putting a PATH into a custom script, but rather the full path to the individual binary?
@unosonic Because not all commands are in the directories in PATH, some users may write their own program or script and put it somewhere else. They may try to run such program/script in beforeShutdown.sh, and exporting PATH may not help, while using absolute path always solves the problem.
Once the users understand this issue, they can of course find better ways to simplify the script, for example putting correct directory in PATH.
I wonder whether beforeShutdown has ever worked well on wittypi3...
from daemon.sh
# run beforeShutdown.sh "$cur_dir/beforeShutdown.sh" >> "$cur_dir/wittyPi.log" 2>&1 & # shutdown Raspberry Pi do_shutdown $HALT_PIN $has_rtc
the "&" at the end kicks execution of beforeShutdown.sh into background, while proceeding with do_shutdown ... Anything which takes longer than a millisecond (eg. sending an email etc.) will be killed by the shutdown process.
@unosonic in fact almost nobody used this feature, the "afterStartup.sh" script was way more popular.
We did not receive any complain about this issue before Witty Pi 3 disontinued.
When we implemented the software for Witty Pi 4, we improved it directly.