Results 1 to 5 of 5

Thread: How can you run a script &/ or commands at shutdown?

  1. #1
    Join Date
    Jul 2013
    Beans
    92

    How can you run a script &/ or commands at shutdown?

    hello,
    how can you run a command(s) or a script at shutdown?
    The ".bash_logout" doesn't work when you shutdown. I know
    I can always first logout, then shutdown, and the logout would run,
    but I would forget to do this alot.

    There is something here:
    http://unix.stackexchange.com/questi...ly-not-working
    , but it is beyond me.


    using Xubuntu 12.04

  2. #2
    Join Date
    Jul 2013
    Location
    Wisconsin
    Beans
    1,437

    Re: How can you run a script &/ or commands at shutdown?

    A better discussion is at http://askubuntu.com/questions/78298...ocess-takes-lo
    Upstart jobs for shutdown are governed by: http://upstart.ubuntu.com/cookbook/#id134

    I would do it in Upstart. Something like:
    Code:
    # Upstart job: /etc/init/my_shutdown_job.conf
    description "My shutdown job"
    
    start on runlevel [06]
    pre-start script
      /path/to/my/shutdown/script
    end script
    When you tell the system to shutdown (runlevel 0), Upstart will check the list of jobs that need to be started or stopped for that condition before actually executing the instruction. This job tells upstart to run the script before the change is executed.

    Caveat: I have done a bunch of Upstart jobs, but have not tested this particular one.
    Last edited by ian-weisser; December 23rd, 2013 at 11:50 AM.

  3. #3
    Join Date
    Sep 2006
    Beans
    7,309
    Distro
    Lubuntu Development Release

    runlevels

    Wouldn't that be just runlevels 0 and 6? Runlevel 5 is just another normal mode of operation.

    Code:
    start on runlevel [06]

  4. #4
    Join Date
    Jul 2013
    Location
    Wisconsin
    Beans
    1,437

    Re: How can you run a script &/ or commands at shutdown?

    Dratted fumbly-fingers. Thanks for pointing it out. Original edited to [06]

  5. #5
    Join Date
    Jul 2013
    Beans
    92

    Re: How can you run a script &/ or commands at shutdown?

    Thanks guys, that worked.
    On my Desktop at logout ( Xubuntu 12.04 ), I have these selections:
    "Log Out" "Restart" "Shut Down" "Suspend"
    I wish there was another one called "Log Out/Shutdown", so that one
    could log out ( and thus have the logout file run ) and shutdown, all
    with one mouse click, in case one forgets to logout first and then
    shutdown. Then the etc/init folder would not have to be messed with.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •