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

[Solved / Archived] Witty Pi 4 L3V7 Scripts not being run before or after reboot

5 Posts
2 Users
0 Likes
89 Views
(@andrew-simpson17)
Posts: 106
Estimable Member Customer
Topic starter
 

Right,

 

I am trying to log some messages to the syslog file when I stop and stop my Rpi.

 

These are my files:

beforeScript.sh

##!/bin/bash
# file: beforeScript.sh
#
# This script will run after Raspberry Pi boot up, and before running the schedule script.
# If you want to change the schedule script before running it, you may do so here.
#
# Remarks: please use absolute path of the command, or it can not be found (by root user).
# Remarks: you may append '&' at the end of command to avoid blocking the main daemon.sh.
#
sudo /usr/bin/logger '******************************************* beforeScript'

 

beforeShutdown.sh

#!/bin/bash
# file: beforeShutdown.sh
sudo /usr/bin/logger '**************************************** beforeShutdown'

 

afterStartup.sh

#!/bin/bash
# file: afterStartup.sh
#
# This script will run after Raspberry Pi boot up and finish running the schedule script.
# If you want to run your commands after boot, you can place them here.
#
# Remarks: please use absolute path of the command, or it can not be found (by root user).
# Remarks: you may append '&' at the end of command to avoid blocking the main daemon.sh.
#
sudo /usr/bin/logger '******************************************* afterStartup'

 

 

I performed two scenarios:

 

I have opened a terminal. I have rebooted the Rpi.

I press my momentaty swicth then is connected to GPIO4. Terh Rpi shuts down. I press the buttin again.  The Rpi starts up.

 

Now when I look in my syslog file I can see no record of my logging.

 

Please advise?

 

 

 

 

 
Posted : 20/12/2024 2:58 pm
(@admin)
Posts: 522
Member Admin
 

Posted by: @andrew-simpson17

I am trying to log some messages to the syslog file when I stop and stop my Rpi.

If you are not sure which file will /usr/bin/logger actually write to, you can just use /usr/bin/echo to append message to any log file you want. For example:

#!/bin/bash
# file: afterStartup.sh
#
# This script will run after Raspberry Pi boot up and finish running the schedule script.
# If you want to run your commands after boot, you can place them here.
#
# Remarks: please use absolute path of the command, or it can not be found (by root user).
# Remarks: you may append '&' at the end of command to avoid blocking the main daemon.sh.
#
/usr/bin/echo '**************************************** afterStartup' >> /var/log/wittypi.log


#!/bin/bash
# file: beforeScript.sh
#
# This script will run after Raspberry Pi boot up, and before running the schedule script.
# If you want to change the schedule script before running it, you may do so here.
#
# Remarks: please use absolute path of the command, or it can not be found (by root user).
# Remarks: you may append '&' at the end of command to avoid blocking the main daemon.sh.
#
/usr/bin/echo '************************************* beforeScript' >> /var/log/wittypi.log


#!/bin/bash
# file: beforeShutdown.sh
#
# This script will be executed after Witty Pi receives shutdown command (GPIO-4 gets pulled down).
# If you want to run your commands before turnning of your Raspberry Pi, you can place them here.
# Raspberry Pi will not shutdown until all commands here are executed.
#
# Remarks: please use absolute path of the command, or it can not be found (by root user).
# Remarks: you may append '&' at the end of command to avoid blocking the main daemon.sh.
#
/usr/bin/echo '************************************* beforeShutdown' >> /var/log/wittypi.log

BTW, there is no need to use "sudo" here, because these scripts will be executed by the root user.

 

 
Posted : 23/12/2024 10:16 am
(@andrew-simpson17)
Posts: 106
Estimable Member Customer
Topic starter
 

Thanks,

 

If I run this from a command line it works. If I test it by either

 

rebooting from command line

shutting down from command line

Pressing the switch connected to GPIO4

 

Then it does not work. Nor do any of my other scripts in your other event handlers?

 

 

 

 
Posted : 24/12/2024 9:58 am
(@admin)
Posts: 522
Member Admin
 

@andrew-simpson17 yesterday I tested my code before I post it in my answer. My confirmed it works.

Rebooting or shutting down the system with command will not work: it doesn't pull down GPIO-4, does it? Without pulling down GPIO-4, how could daemon.sh know the system is off/reboot?

Pressing the button should work (and I tested it). If your daemon.sh has been correctly registered to run on boot, I run out of clue then.

 
Posted : 24/12/2024 12:46 pm
(@andrew-simpson17)
Posts: 106
Estimable Member Customer
Topic starter
 

@admin 

Hi

 

Yes I know command actions will not work.  I was trying to say I restarted everything for changes to take affect. Just explained it badly.

But it still did not work. Is it because the drives are unmounted do you think?

 

 

 
Posted : 24/12/2024 3:28 pm
Join Waitlist We will inform you when the product arrives in stock. Please leave your valid email address below.