LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-17-2018, 08:25 AM   #1
sareniki
LQ Newbie
 
Registered: Oct 2018
Posts: 2

Rep: Reputation: Disabled
zenity auto-close instantly closes


Hi all,

I'm trying to make this simple script work. If I remove the zenity auto-close option, the progress bar goes nicely from 100 to 0, and time counts down. But I don't get an exit code to use, and the zenity box stays there.
If I do use the auto-close option, the zenity message instantly disappears without counting down, with an exit code 0.

I would like this to close automatically after timeout (10 minutes, adjustable), with the same exit code as if I would click the "OK" button, and also being able to cancel the automatic shutdown, by clicking "cancel".

Any ideas what I'm doing wrong here?

Thanks in advance!!

code:


Code:
#!/bin/bash

CD=10  # number of minutes before shutdown

CDA=$CD
(
while [ $CDA != 0 ]
do
	echo "# Shutdown? \nAutomatic shutdown in $CDA minutes" 
	BAR=$(($CDA * 100 / $CD))
	echo $BAR ; sleep 60
	(( CDA-- ))
done
) | 
zenity --progress --title="autoshutdown" --auto-close


if [ "$?" = 0 ] ; then
	notify-send 'shutdown cancelled'
else
	shutdown -p now
fi

Last edited by sareniki; 10-17-2018 at 08:36 AM.
 
Old 10-17-2018, 02:37 PM   #2
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 12,471
Blog Entries: 9

Rep: Reputation: 3375Reputation: 3375Reputation: 3375Reputation: 3375Reputation: 3375Reputation: 3375Reputation: 3375Reputation: 3375Reputation: 3375Reputation: 3375Reputation: 3375
you certainly don't need the brackets around the while loop, you can put the pipe right behind 'done'.

i just tried this, and it's working as desired:
Code:
$ i=0;while sleep 1; do echo $((i++)); done | zenity --progress --title="autoshutdown" --auto-close
$ zenity --version
2.32.1
maybe the error is with the rest of your script, and not the zenity command itself?
 
Old 10-17-2018, 05:06 PM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 19,028

Rep: Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890
Welcome to LinuxQuestions.

From the man pages.
Quote:
--auto-close Close dialog when 100% has been reached
Since your starting at 100% zenity will instantly close. What you need to do is have your text count down and your bar count up. Here is a quick loop.

Code:
i=90
while sleep 1; do 
  y=$((100-$i))
  echo "# Shutdown? \nAutomatic shutdown in $y minutes"
  echo $((i++))
done | zenity --progress --title="autoshutdown" --auto-close

Last edited by michaelk; 10-17-2018 at 05:08 PM.
 
2 members found this post helpful.
Old 10-18-2018, 03:42 AM   #4
sareniki
LQ Newbie
 
Registered: Oct 2018
Posts: 2

Original Poster
Rep: Reputation: Disabled
Wow. How could I have missed that... lol
Thanks!

For anyone interested, my perfectly working script now:

Code:
#!/bin/bash

CD=10  # number of minutes before shutdown

CDA=$CD
CDB=0
TOTAL=$(($CD * 60))  #minutes to secs
SEC=0
SCDN=1
(
while true
do
	echo "#Automatic shutdown in $CDA minutes, $SEC seconds.\nPress cancel to prevent automatic shutdown." 
	BAR=$(($CDB * 100 / $TOTAL))
	echo $BAR ; sleep 1
	if ! (( $CDB % 60 )) ; then
		(( CDA-- ))
		SCDN=1
	fi
	(( CDB++ ))
	SEC=$((60 - $SCDN))
	(( SCDN++ ))
done 
) | zenity --progress --title="autoshutdown" --auto-close

if [ "$?" = 1 ] ; then
	notify-send 'shutdown cancelled'
else
	notify-send 'shutdown initiated'
	sleep 3
	shutdown -p now
fi

Last edited by sareniki; 10-23-2018 at 10:40 AM. Reason: making things complete
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to get zenity code if user close zenity window pedropt Programming 4 03-03-2017 12:13 PM
Evolution opens then instantly closes itself again andreasummerfield Linux - Newbie 4 10-24-2011 04:10 AM
Sauerbraten windows closes instantly. OS: Sabayon 4.0 Infasoft Linux - Newbie 1 03-19-2009 08:07 PM
Chromium BSU window closes instantly Kamex SUSE / openSUSE 0 02-23-2005 07:26 AM
HLDS closes when I close telnet MarleyGPN Linux - General 1 04-26-2003 05:34 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration