You are not logged in.

#1 2011-10-23 01:08:42

sweetthdevil
Member
Registered: 2009-10-20
Posts: 417

Issue with zenity shutting down script

Hi all,

I am running a script at a certain time, to check weather or not the computer must remain on or not, it use to work but for some reason it doesn't any more. And regardless which reply you give it it will shut down every time.

I would also like to improve it but do not know how to approach the issue within the same script easily, if by the time (22:45) the user wants to carry on working, then the script should sleep for 'x minutes'  then start again asking the question, any idea to do it easily without adding too many lines?

#!/bin/bash

current_epoch=$(date +%s)
target_epoch=$(date -d '22:45' +%s)

sleep_seconds=$(( $target_epoch - $current_epoch ))

sleep $sleep_seconds

zenity --question --timeout 10 --title="The computer has finish is work" \
   --text="The computer has finish is work!       \
	  Should the computer remain on?"

if [[ $? == 0 ]] ; then
   zenity --info --text="Please do not forgot to power down the computer when finish!"

else

pkill cam2.sh & pkill desktop.sh & pkill ffmpeg &

sleep 5
   
procall=`pgrep -u $(whoami) -t tty1`        #get all users proceses
procbas=`pgrep -u $(whoami) -t tty1 bash`    #get the login bash pid
procxin=`pgrep -u $(whoami) -t tty1 xinit`    #get the xinit pid

# nicely terminate all users processes except bash & xinit
for p in $procall; do
   if [ "$p" != "$procbas" ] && [ "$p" != "$procxin" ]; then
        kill -TERM $p
    fi
done
sleep 2

# now KILL the processes that are still alive
for p in $procall; do
    if [ "$p" != "$procbas" ] && [ "$p" != "$procxin" ]; then
       kill -KILL $p
    fi
done
sync

# and finally . . . . we shutdown via policykit/dbus
dbus-send --system --print-reply --dest="org.freedesktop.ConsoleKit" /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Stop

fi

the other issue is, if the user is connected passed the 22:45 at night  (so in between 22:46 and 23:59) the script will execute right away - instead of sleeping until the next 22:45 (next day)

Many thanks,

Looking forward for your replies,

Last edited by sweetthdevil (2011-10-23 01:33:10)

Offline

#2 2011-10-23 10:25:09

sweetthdevil
Member
Registered: 2009-10-20
Posts: 417

Re: Issue with zenity shutting down script

After a bit of testing I have reported a bug on the latest version of the package, the --timeoption when use always return a negative vibe.

Downgrading to the previous version fixed the issue.

https://bugs.archlinux.org/task/26582

Last edited by sweetthdevil (2011-10-23 10:56:51)

Offline

Board footer

Powered by FluxBB