Is it possible to detect that an impending shutdown (or reboot) is in progress?
1
vote
1
answer
1152
views
I'm trying to write a script in bash that I intend to start on system startup and end on system shutdown. The idea is to create a system uptime tracker for myself.
For the purpose, I want to save the uptime of each day in a file. But I can't figure out a way to know when a shutdown has been triggered by the user (or by the system). This is very important because otherwise I won't be able to save the session end time in the file.
Also it could have been done by running a loop after some x amount of time and saving the current uptime. But I think it's inefficient and at the same time will perform unnecessary disk operations.
There might be readymade solutions available for this (or perhaps a native command), but I want to code it myself.
Asked by Shourya Shikhar
(169 rep)
Dec 18, 2021, 11:57 AM
Last activity: Dec 18, 2021, 12:51 PM
Last activity: Dec 18, 2021, 12:51 PM