Run a script before and after reboot automatically and send output to two locations.

Hello Team .

I am working a health check script ( bash) to run on linux server ( RedHat) and requirements are

  1. The o/p of script need to be send to two diff files . I am testing with tee command . But I am not successful yet , any recommendations if that is the right approach ?
  2. The same script need to run by itself just before power off and right after power on . If I keep the script under /etc/init.d , it will run right after power on OR to set up a cron with @reboot . But what I am looking is if I can have a logic in script which need to identify whether the state of the server is power off or on , If so send the output from one of the o/p files generated(from #1) .

Hope it makes sense.

Greetings and welcome to our forum

depends what you call right after...
Without knowing your OS and its version no one will take the risk of giving you any advise, as start stop implementation is OS dependant

my apologies. I will edit to make it more clear.

--- Post updated at 11:08 PM ---

sorry, not sure If I got you right , I was referring to the script I am (still) working on on the whole context.