I'm a beginner in the program.
I would like to run a simple script during shutdown and reboot using Raspberry Pi 3model B, but there is no sign that the script has been executed and it fits in.The content of the script is simply a script that writes the string test to a file.The expected value is that a log file will be generated after a shutdown or reboot, but we decided that the script was not running because the file was not generated.By the way, when I started the terminal and ran the following script, I did what I wanted.I think there may be a problem with how to register the service.
The distribution is Ubuntu 16.04.
The script includes the following:
I referred to the link below.
http://qiita.com/toshihirock/items/4c8c3987b8837989d6fb
#!/bin/bash
name = "test"
lock_file="/var/lock/subsys/${name}"
log_file="/var/log/${name}.log"
echo${name}>>${log_file}
start(){
touch${lock_file}
# Calling other scripts (currently commenting out)
}
stop(){
rm-f${lock_file}
}
case"${1}" in
start)
start
;;
stop)
stop
;;
*)
echo "Usage:${0}{start|stop|restart}"
;;
esac
Here's what we did.
·I put the above script (test) in /etc/init.d/.
·Symbolic link (S00 test) was created in /etc/rc0.d/ and /etc/rc6.d/.
·The test/S00 test permission is in an executable state.
·The sysv-rc-conf command is used to start the test at run levels 0 and 6.
>$sysv-rc-conf --list
test0:on 6:on
·In addition, I put a test in /var/lock/subsys/.
I'm ashamed that I didn't understand it properly.
If you've had a similar experience, could you tell me the solution?
Thank you for your cooperation.
In addition, we put a test in /var/lock/subsys/.
/var/lock/subsys/{$name} is a lock file indicating that the script is started, so if it exists, the script is considered already running and will not start.
start(){
touch${lock_file}
You don't have to create it yourself because you're creating it here.
Why don't you have crontab run the script using @reboot?
$echo'@reboot/path/to/script' | crontab
$ crontab -l
@reboot/path/to/script
Debian CRONTAB (5)
-----
string meeting
------ -------
@reboot Runonce, at startup.
@yearly Runonce a year, "00 1 1 *".
@annually (same as @yearly)
@monthly Run once a month, "00 1 * *".
@weekly Run once a week, "00 * * 0".
@dailyRunonce a day, "00 * * *".
@midnight(same as@daily)
@hourly Run once an hour, "0****".
References
https://manpages.debian.org/stretch/manpages-ja/crontab.5.ja.html
916 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
613 GDB gets version error when attempting to debug with the Presense SDK (IDE)
578 Understanding How to Configure Google API Key
620 Uncaught (inpromise) Error on Electron: An object could not be cloned
© 2024 OneMinuteCode. All rights reserved.