Tiny Core Linux
Tiny Core Base => TCB Talk => Topic started by: halma on September 18, 2020, 09:18:24 AM
-
Hey all
id like to know what is the usual way under tinycorelinux 11.1 to run a shell script at shutdown or restart?
/opt/shutdown.sh seems not working...
/etc/init.d/myscript
#!/bin/busybox ash
# /etc/init.d/myscipt
#
./etc/init.d/tc-functions
useBusybox
#
#
# sichert log Dateien aus /var/log
echo "log dateien wernden gesichert..."
zielverzeichnis="/mnt/xvda/logs"
datum="$(date +"%Y-%m-%d_%H_%M")"
cd /var/log
for datei in $(ls -1); do
tar czf "$zielverzeichnis/${datei}_${datum}.tar.gz" "$datei"
done
is simlinked from the /home/tc/myscript.sh to /etc/init.d/myscript and a modified inittab seems also not working
cat /etc/inittab
# /etc/inittab: init configuration for busybox init.
# Boot-time system configuration/initialization script.
#
::sysinit:/etc/init.d/rcS
# /sbin/getty respawn shell invocations for selected ttys.
tty1::respawn:/sbin/getty 38400 tty1
#tty2::respawn:/sbin/getty 38400 tty2
#tty3::respawn:/sbin/getty 38400 tty3
#tty4::askfirst:/sbin/getty 38400 tty4
#tty5::askfirst:/sbin/getty 38400 tty5
#tty6::askfirst:/sbin/getty 38400 tty6
# Stuff to do when restarting the init
# process, or before rebooting.
::restart:/etc/init.d/myscript
::restart:/etc/init.d/rc.shutdown
::restart:/sbin/init
::ctrlaltdel:/sbin/reboot
::shutdown:/etc/init.d/myscript
::shutdown:/etc/init.d/rc.shutdown
hvc0::respawn:/sbin/getty 38400 hvc0
How can i run a script at shutdown/restart ??
Thanks a lot and Best Regards
-
Hi halma
If you shut down using poweroff or restart using reboot, no scripts will be run. Those are busybox commands.
If you run:
exitcheck.sh reboot
or
exitcheck.sh shutdown
it will call /opt/shutdown.sh.
If you use the Exit icon in the GUI, it too will call exitcheck.sh.
If you are trying to backup inittab and the symlink in /etc/init.d, it won't work. The restore happens way too late.
-
Hi Rich :)
the exitcheck.sh command is a nice, let me call it: "workaround". Thats not the solution i want to have because on mostly every linux or bsd system the way to restart or shutdown from a user is "sudo reboot/shutdown". So mostly as a normal behavior or how I learned it and how to act accordingly from the subconscious and excuse me if I say so but I don't want to learn and memorize a new command that only works for a single system like microsoft stuff.I would like to use the command that is usually standard under a linux system: sudo reboot/shutdown
I have some Questions about the reboot/shutdown behavior of tinycorelinux. The "rc.shutdown" is the only command/script which runs at reboot/shutdown. Is this "rc.shutdown" name hardcoded?
Why is myscript not executed and also other scripts before the "rc.shutdown" starts after i have send a reboot/shutdown command to the system?
I think i have correctly inittab configured seen in the first post of this thread.
Thanks a lot
-
inittab is read so early in boot, to make changes in it read you need to remaster those in, instead of using backup.
edit: alternatively, sending SIGHUP to init after changing the file may work.
-
Hi halma
Maybe this will work. Edit /etc/init.d/rc.shutdown and have it call your script like this:
#!/bin/sh
# /etc/init.d/rc.shutdown - used by /etc/inittab to shutdown the system.
#
. /etc/init.d/tc-functions
useBusybox
/etc/init.d/myscript
clear
# Sync all filesystems.
echo "${BLUE}Syncing all filesystems."
sync; sync
----- Snip -----
Add etc/init.d/rc.shutdown to your backup.
-
Hello Rich,
i had the same idea before but i dont like "hackarounds" cause its not the usually/official way, but this seems at the moemnt the only way to run a script at reboot/shutdown. Append this lines to the bootlocal.sh is doing the job
# insert personal shellscript into /etc/init.d/shutdown.rc
echo "appending personal reboot/shutdown shellscript to /etc/init.d/rc.shutdown"
shellscript_to_run="/my/script"
if ! grep "$shellscript_to_run" /etc/init.d/rc.shutdown >/dev/null; then
sed -i '/useBusybox/a\
\
# run a script at reboot/shutdown\
'"${shellscript_to_run}"'' /etc/init.d/rc.shutdown
fi
Thanks a lot
*i cannot mark the thread a solved*
-
Hi halma
Adding a command to modify /etc/init.d/shutdown.rc from /opt/bootlocal.sh is another way of doing it. This should work
quite well if you update your sytem. Kudos on your sed skills.
... *i cannot mark the thread a solved*
That's what I'm here for. :)