Detecting System Restart or Shutdown?

Leo "TheHobbit" Cacciari leothehobbit at gmail.com
Thu Apr 14 09:41:45 UTC 2011


Il 04/13/2011 12:41 PM, waqar afridi ha scritto:
> Hello Dear List
>
> Is there any method through which I can Detect that the System was
> recently shutdown or Restarted?
>
> *Explanation:*
>
> I am making a utility that will Store some Files on HardDisk. I want
> the utility to Detect if the System
> is newly Booted. If it is, It should delete those Files and Create
> fresh Once.
Hi,
someone else gave you ideas for answering the question you made, but
given the explanation of why you made that question, I think that maybe
you did not pose the right question. If you want to delete the old files
and create new ones when the system is rebooted you should probably use
a init.d script (i.e. a script installed in /etc/init.d). These scripts
are normally invoked with a single argument, one of the 'commands' 
start, stop, restart, reload, force-reload (see /etc/init.d/skeleton).

To implement what you require, I'll write a script as above, which
creates the files when invoked with start and deletes them when invoked
with stop, then I'll arrange the system for call the script with 'start'
on system start and with 'stop' when shutting down (see the
documentation about update-rc.d for how to do it). This will delete the
files when the system is stopped (or when it goes down for rebooting)
and will create it again when the system comes up.

Hoping to be of service... :)

TH

-- 
Leo "TheHobbit" Cacciari
Aliae nationes servitutem pati possunt populi romani est propria libertas

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20110414/d239513b/attachment.html>


More information about the ubuntu-users mailing list