I don't want the system to shutdown in the middle of the upgrade, but I've already started the upgrade in the GUI.

Is there a better way, maybe involving the apt lock?

EDIT: Thank you for all the helpful suggestions. Hopefully this helps the next person. My upgrade actually finished on its own while I was posting. ๐Ÿ˜‚

you are viewing a single comment's thread
view the rest of the comments
[โ€“] 20 points 4 months ago (14 children)

If you can run sudo without a password, you could do something like:

sudo apt update && sudo shutdown -h 5

The && operator will only execute the next instruction if the first returns a zero (no error) code upon completion.

Then just run that command about every 5 minutes and it'll shut down once the install dishes, which releases the lock so apt upgrade can go (presuming apt upgrade needs the lock - I don't remember if it does.)

Alternatively, you could ps auxw | grep for the pid of the upgrade. Then keep running a ps for that pid, and once you don't see it, shutdown.

  • source
  • hideshow 14 child comments
  • [โ€“] 11 points 4 months ago (5 children)

    If you can run sudo without a password, you could do something like:

    There's no need for password-less sudo. Instead, you can use bash -c to run a set of commands via sudo:

    sudo bash -c "while true;do apt update && shutdown -h 5; sleep 5m;done"
    
  • source
  • parent
  • hideshow 5 child comments
  • [โ€“] 10 points 4 months ago (3 children)

    Why do you need the while true?

  • source
  • parent
  • hideshow 3 child comments
  • [โ€“] 4 points 4 months ago (1 child)

    I suppose it would be useful for flakey internet connection, then your update would restart 5 minutes after losing the connection. It surely has a yucky aftertaste, though.

  • source
  • parent
  • hideshow 1 child comment
  • [โ€“] 4 points 4 months ago

    No, the idea was that apt update would keep failing while the system upgrade was running (and holding the lock):

    $ apt update
    E: Could not get lock /var/lib/apt/lists/lock. It is held by process 1704856 (apt)
    N: Be aware that removing the lock file is not a solution and may break your system.
    E: Unable to lock directory /var/lib/apt/lists/
    

    But there are better ways of waiting for a process to finish, that other people have shared

  • source
  • parent
  • [โ€“] 9 points 4 months ago* (5 children)

    I was today years old when I learned that && on the command line is not just a after this do this shortcut, but rather how it is used literally everywhere else sort of thing. I am not a very bright knife in the shed.

  • source
  • parent
  • hideshow 5 child comments
  • [โ€“] 5 points 4 months ago

    From the old world of UNIX: Using UNIX is always a series of small epiphanies. You will keep finding new options, tools, ideas,, and shell snippets that will continually expand your skills.

    I've been using UNIX and then Linux since 1996. I find new little bits any time I go look. It's a lifetime of curiosity awaiting for you.

  • source
  • parent