WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: how to exec a script when reboot system  (Read 1696 times)

Offline lovelypp

  • Jr. Member
  • **
  • Posts: 51
how to exec a script when reboot system
« on: March 27, 2023, 06: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!

Online Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 1248
Re: how to exec a script when reboot system
« Reply #1 on: March 27, 2023, 09:59:19 AM »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11651
Re: how to exec a script when reboot system
« Reply #2 on: March 27, 2023, 10: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

Offline lovelypp

  • Jr. Member
  • **
  • Posts: 51
Re: how to exec a script when reboot system
« Reply #3 on: March 29, 2023, 09:19:29 PM »
thanks