Tiny Core Linux

Tiny Core Base => TCB Talk => Topic started by: lovelypp on March 27, 2023, 03:19:04 AM

Title: how to exec a script when reboot system
Post by: lovelypp on March 27, 2023, 03:19:04 AM
there is a script /opt/shutdown.sh,but when reboot, it is not executed.

I want to execute a script when user run reboot, how ?
thanks!
Title: Re: how to exec a script when reboot system
Post by: Paul_123 on March 27, 2023, 06:59:19 AM
The shutdown script gets ran from exitcheck.sh

https://github.com/tinycorelinux/Core-scripts/blob/master/usr/bin/exitcheck.sh
Title: Re: how to exec a script when reboot system
Post by: Rich on March 27, 2023, 07:03:09 AM
Hi lovelypp
If you call:
Code: [Select]
exitcheck.sh rebootthen  /opt/shutdown.sh  will get called right before the system reboots.

If you call:
Code: [Select]
exitcheck.sh poweroffthen  /opt/shutdown.sh  will get called right before the system powers off.

When using a GUI, the  Exit  icon and the  Exit  from the desktop menu call  exitcheck.sh  the same way.

If you want  /opt/shutdown.sh  to know it was called to  reboot  or  poweroff , add this to  /opt/shutdown.sh:
Code: [Select]
ACTION="$(busybox ps | grep "exitcheck.sh")"
case "$ACTION" in
    *"reboot"*)
    # Commands to execute right before
    # you reboot go here.
    ;;

    *"poweroff"*)
    # Commands to execute right before
    # you power off go here.
    ;;

    *)
    # What to do if exitcheck.sh gets called
    # with no or incorrect value goes here.
    ;;
esac

If you want to run something after you reboot, add this line to the reboot section:
Code: [Select]
touch /etc/sysconfig/tcedir/REBOOT
Then add the following to  /opt/bootsync.sh  or  /opt/bootlocal.sh:
Code: [Select]
if [ -e /etc/sysconfig/tcedir/REBOOT ]
then
    rm -f /etc/sysconfig/tcedir/REBOOT
    # Commands to execute after
    # you reboot go here.
fi
Title: Re: how to exec a script when reboot system
Post by: lovelypp on March 29, 2023, 06:19:29 PM
thanks