Can anyone offer any advice on how to modify the script below to work on a new system we have, that has no graphics capability? We admin the system through a serial RAS device. I've tried running the below script through the RAS and through an ssh -X session. It failed with something like "GTK unable to produce display". Python scripts however do produce menus and such on screen and I don't understand the difference. Any help/advice is greatly appreciated. Thank you.
This script is supposed to produce a text box on screen, that our installers enter a 4 digit code on. That code is checked for validity and if it is, the script completes. I have several other scripts just like this one, all with the same problem. Is is zenity????
#!/bin/bash
VER=`zenity --entry --text "Please enter the ACG pgm number:" --title "Version Entry"`
if [ -z "$VER" ]; then
echo "ERROR: Version entry was not provided."
exit 1
fi
IS_OK=`echo $VER | egrep "[0-9]{4}"`
if [ -z "$IS_OK" ]; then
zenity --question --text "'$VER' does not appear to be a
valid version string.
Continue anyway?"
if [ $? -ne 0 ]; then
echo "ERROR: Invalid version entry."
exit 1
fi
fi
echo $VER > /etc/acg-oe-pgm
Hi,
Yes, the issue here is most likely to be zenity
, as you say. zenity
is a utility for displaying dialog boxes in an X Windows graphical environment. If you're running this server headless (i.e. you have no monitor connected and are interacting with it purely over a serial link) then zenity
isn't going to work. Your best bet would be to switch out zenity
for another text-only utility such as dialog
, which can display interactive full-screen text mode dialog boxes to query the user for information. That should work in any terminal session regardless of whether the script was being started in an xterm running in X11, on a text mode virtual console, or over a serial link. If you check out the man
page for dialog
it'll give you a description of how it works, but it shouldn't be too hard to re-work your script to use one rather than the other.
2 Likes
The following shell script emulates zenity on a console device.
#!/bin/bash
if [ -n "$DISPLAY" ] && xdpyinfo >/dev/null 2>&1
then
graphics=1
else
graphics=
fi
# a wrapper for zenity that does console I/O if no graphics
dialog(){
if [ -n "$graphics" ]
then
zenity "$@"
return
fi
do_text= text= do_yes_exit=
for arg
do
if [ -n "$do_text" ]
then
text=$arg
do_text=
else
case $arg in
(--text) do_text=1;;
(--question) do_yes_exit=1;;
esac
fi
done
read -p "$text: " input
if [ -z "$do_yes_exit" ]
then
echo "$input"
return
fi
case $input in
([Yy]*) return 0;;
esac
return 1
}
VER=$(
dialog --entry --text "Please enter the ACG pgm number:" --title "Version Entry"
)
if [ -z "$VER" ]; then
echo "ERROR: Version entry was not provided."
exit 1
fi
case $VER in
([0-9][0-9][0-9][0-9])
;;
(*)
dialog --question --text "'$VER' does not appear to be a
valid version string.
Continue anyway?"
;;
esac
if [ $? -ne 0 ]
then
echo "ERROR: Invalid version entry."
exit 1
fi
echo "$VER" > /etc/acg-oe-pgm
1 Like
Just wanted to take a moment and thank you all for your help. It's greatly appreciated. Cheers~