Score:1

How to check if unattended upgradeis currently running

lb flag

I was wondering if there was a way to check if unattended upgrade is currently doing its thing (from a bash script)

I want to use a cron interval to run a script that will periodically check to see if unattended upgrades is running and, if it is, send a notice to a webhook.

(The target of the webhook will then not attempt to do things on the server if unattended upgrades is running).

Thanks in advance for any ideas.

Score:1
at flag

you can save this script and link a cron job to it, ps -C checks whether any process is using apt "which is usually for upgrading" and grep apt checks whether the output of ps -C apt contains a result.

#!/bin/bash

command=$(ps -C apt | grep apt)

if [[ -n $command ]]; then

    # will execute if the system is being upgraded
    # to be more precise, it will execute if the process apt is running

fi
traderdev avatar
lb flag
Thank you, that works. I wonder if there's a way to detect when apt starts and then run the script instead of having to check with cron.
Amirreza avatar
at flag
then there should be a while loop wrapping around the whole script, it's a bit resource intensive: `while [ true ] #new line do #new line # code goes here; sleep 0.05 #new line done`
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.