Cool stuff for Raspberry Pi, Arduino and all electronics hobby projects
Notifications
Clear all

[Solved / Archived] beforeshutdown.sh not working (Witty Pi 3 Mini)

8 Posts
2 Users
1 Likes
540 Views
(@unosonic)
Posts: 0
Active Member Customer
Topic starter
 

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

 
Posted : 19/10/2023 8:46 am
(@admin)
Posts: 479
Member Admin
 

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
 
Posted : 19/10/2023 9:13 am
(@unosonic)
Posts: 0
Active Member Customer
Topic starter
 

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.

 
Posted : 22/10/2023 10:25 am
(@admin)
Posts: 479
Member Admin
 

Posted by: @unosonic

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.

 
Posted : 22/10/2023 4:51 pm
(@unosonic)
Posts: 0
Active Member Customer
Topic starter
 

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?

 

 
Posted : 23/10/2023 11:06 am
(@admin)
Posts: 479
Member Admin
 

@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.

 
Posted : 23/10/2023 11:53 am
(@unosonic)
Posts: 0
Active Member Customer
Topic starter
 

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.

 
Posted : 24/10/2023 11:35 pm
(@admin)
Posts: 479
Member Admin
 

@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.

 

 
Posted : 25/10/2023 3:11 pm
Chip Thomas reacted
Join Waitlist We will inform you when the product arrives in stock. Please leave your valid email address below.