Results 1 to 7 of 7
I have the following piece of script where when a user logs into their account they are confronted with the following dialog with an OK or Cancel. The path and ...
- 05-06-2009 #1
Zenity Login Banner
I have the following piece of script where when a user logs into their account they are confronted with the following dialog with an OK or Cancel. The path and where to insert the code is explained below. My question is, how do I set up the dialog for when the user selects OK they enter their session where when a user selects Cancel then it cancels out of the session and returns to the login screen?
1. $ vi /etc/gdm/PreSession/Default
2. Add the commands given below after the PATH and IFS directive:
3.
Code:# Login banner /usr/bin/zenity --question --text "Standard\\n Disclaimer\\n Text" if ( test 1 -eq $? );then # To avoid staring at a blank screen for next 10 second, # and to miss the date with xsession-error dialog /usr/bin/zenity --info --text="Loggin Out in 10secs" 1 20 & sleep 10 exit 1 fi
- 05-07-2009 #2
I found that if you put a
at the end of:; echo $?
/usr/bin/zenity --question --text "Standard\\n Disclaimer\\n Text"
then you get a 0 for yes and a 1 for Cancel
I don't know the rest of the script because I am a novice. I would like it to go something like this:
If 0 is selected; then enter GUI
else if 1 is selected; then logout
fi
Can someone put this into script?
- 08-19-2009 #3Just Joined!
- Join Date
- Aug 2009
- Posts
- 15
Also, if anyone knows how to use the Zenity "--progess" dialog so that it will display a progress bar if someone clicks "--questions" Cancel option that would be nice. I'm trying to get the "sleep 10" to also count down with the "--progess" bar. The 10 second count down is useful to prevent Red Hat from giving you that "Your session lasted less than 10 seconds..." blurb.
- 09-02-2009 #4Just Joined!
- Join Date
- Sep 2009
- Posts
- 1
To get zenity to move the progress bar, you need to send numbers to STDIN through a pipe to zenity. If you add --auto-close it will exit when 100% is reached.
Code:TIMEOUT=10 ( SEC=$TIMEOUT; while [[ $SEC -ge 0 ]]; do echo `expr \( \( $TIMEOUT - $SEC \) \* 100 / $TIMEOUT \)`; echo "#Logout will occur in $SEC seconds."; SEC=`expr $SEC - 1`; sleep 1; done; ) | /usr/bin/zenity --progress --auto-close --text "Logout will occur in $TIMEOUT seconds."
Last edited by msfraser; 09-02-2009 at 02:57 AM. Reason: replace 'while [[ $SEC -gt 0 ]];' with 'while [[ $SEC -ge 0 ]];'
- 09-02-2009 #5Just Joined!
- Join Date
- Aug 2009
- Posts
- 15
Thanks msfraser. Works great.
So to sum it up:
# Login banner display with option to Cancel and exit.
/usr/bin/zenity --question --text "Between the Quotes enter here a whole bunch of stuff for your users to read so that they will not get in trouble and so they will know all the stuff they need to know before they login, and on and on.
Press Enter where needed to make it presentable and readable.
At the bottom of mine I added:
If you agree with these terms then click Ok to login.
If you do not agree with these terms then click Cancel to exit."
# Did the user click OK or Cancel? A Cancel returns a 1 and if it is
# a 1 then start the Exit/Logout/Cancel process.
if ( test 1 -eq $? );then
# This section was supplied by msfraser.
TIMEOUT=10
(
SEC=$TIMEOUT;
while [[ $SEC -ge 0 ]];
do
echo `expr \( \( $TIMEOUT - $SEC \) \* 100 / $TIMEOUT \)`;
#echo This echo I never see. So I just commented it out.
SEC=`expr $SEC - 1`;
sleep 1;
done;
) | /usr/bin/zenity --progress --auto-close --text "Returning to login screen in $TIMEOUT seconds."
exit 1
fi
#### THERE YA GO.#####
- 09-02-2009 #6Just Joined!
- Join Date
- Aug 2009
- Posts
- 15
On mirror caveat. When the --progess box comes up there is still a Cancel Button on it. If you click that cancel button, you are logged in. I have put in an Enhancement Request with the zenity folks for a --nocancel option that will remove or prevent someone from using the Cancel Button.
- 10-12-2009 #7Just Joined!
- Join Date
- Aug 2009
- Posts
- 15
Update ... regarding the minor caveat (not mirror caveat) mentioned above.
If you modify the script after the pipe to:
( /usr/bin/zenity --progress --auto-close --text "Returning to login screen in $TIMEOUT seconds." ; echo $? > /tmp/somefilename )
sleep 10
exit 1
Now it, for me at least, does not continue with the login when the Cancel Button is clicked. I was just experimenting with the code a the command line and stumbled on this. The addition of the parenthesis, semicolon and echo did the trick, with another sleep 10 to avoid that login message when it is less than 10 seconds.


Reply With Quote