Sunday, April 28, 2024
 Popular · Latest · Hot · Upcoming
3
rated 0 times [  3] [ 0]  / answers: 1 / hits: 857  / 2 Years ago, fri, april 22, 2022, 8:43:30

when logging out to a different user, shutting down, or restarting the machine sometimes I can get this message




some programs are still running




program list




waiting for programs to finish. interrupting these programs may cause
you to lose work




Is there any way that ubuntu can automatically detect when these programs have completed their task before closing down?
I understand there is an issue with programs that might have crashed. But some other programs such as Ubuntuone might need some additional time to sync before the system can shutdown






Here you are, this is the parse output. I have got no clue of what can be done with it, but I am quite excited to see some magic!



martin@ubuntu-desktop:~$ u1sdtool --status
State: QUEUE_MANAGER
connection: With User With Network
description: processing the commands pool
is_connected: True
is_error: False
is_online: True
queues: IDDLE


the only difference when the daemon is syncing is the last line that can become



queues: WORKING


or



queues: WORKING_ON_BOTH

More From » 11.04

 Answers
5

I am not sure if that would be nice, can you imagine if you had to w8 for 1Gb of files to be synced before shutdown? Doesn't it make more sense that the close signals are sent to the programs so they can quit and if there is further work then it can be resumed on after booting again.



Even Windows only allows 30 secs before it forces close on programs for shutdown.



I really don't see how can this be useful! If I order a shutdown I want that thing closed asap and boot up asap, not wait for the programs to do idontknowwhat. After all, it was my responsibility that started the shutdown, I should know when its a good time or not.



Edit (read all the comments bellow!):



Here is the script that checks the current status of UbuntuOne and shuts down only when status is idle.



#! /bin/bash

gracetime_given=false

while true; do
u1sdtool_status=$(u1sdtool --status | grep -o 'queues: IDLE')
timestamp=$(date +%H:%M:%S)
if [ "$u1sdtool_status" = "queues: WORKING" -o "$u1sdtool_status" = "queues: WORKING_ON_BOTH" ]; then
echo "$timestamp - UbuntuOne has not finished sync, waiting for conclusion."
echo "Re-checking in 30 seconds."
gracetime_given=false
sleep 30
elif [ "$u1sdtool_status" = "queues: IDLE" ]; then
if [ $gracetime_given = false ]; then
echo "u1sdtools seems to be idle at the moment..."
echo "Giving u1sdtool some grace time, rechecking in 10 seconds."
gracetime_given=true
sleep 10
else
echo "This is where you shutdown!!!"
sleep 5
sudo shutdown -h now
fi
else
echo "Something is really wrong!!!"
break
fi
done


To use it you need to do the following, on the terminal you need to use sudo visudo and add this line at the end of the file <yourusername> hostname=NOPASSWD: /sbin/shutdown -h now so that no password is necessary to shutdown your computer using account.



After that you need to save the script anywhere (), you need to use chmod 755 <nameofthescript.sh> to make it executable.



Then you can just run the scrip and see how it works:




  • gets the current status of UbuntuOne

  • if not idle re-checks to see if its idle every 30 secs

  • if idle will give it 10 more secs and recheck if the status is still idle

  • if it is still idle it will shutdown using shutdown -h now



Hope this works and comment as you want on the code as long as you understand that this is actually my very first bash script!



Gl and hf ;)


[#43282] Saturday, April 23, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
uestred

Total Points: 464
Total Questions: 104
Total Answers: 112

Location: Israel
Member since Wed, Apr 14, 2021
3 Years ago
;