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