Bash script won't run because hardware won't produce display


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Bash script won't run because hardware won't produce display
# 1  
Old 06-26-2019
Bash script won't run because hardware won't produce display

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????

Code:
#!/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

# 2  
Old 06-28-2019
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.
These 2 Users Gave Thanks to drysdalk For This Post:
# 3  
Old 06-28-2019
The following shell script emulates zenity on a console device.
Code:
#!/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

This User Gave Thanks to MadeInGermany For This Post:
# 4  
Old 07-06-2019
Thanks to all

Just wanted to take a moment and thank you all for your help. It's greatly appreciated. Cheers~
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

While read won't run keyboard function

I am using while read do/ done to retrieve menu item. Works as advertised, no problem. I am using this hack function "pause" to stop script execution and wait for keyboard "enter" key to continue. Sort of break point function. Also works fine with one exception - it does not work when used... (4 Replies)
Discussion started by: annacreek
4 Replies

2. Shell Programming and Scripting

Nested double quotes won't work in my bash script?

In a bash script I have: LSCMD="find /project/media/ -mindepth 2 -maxdepth 2 -name \"files*pkg\"" ALL_PACKAGES=$( $LSCMD | sort 2>/dev/null) But I get nothing returned. It's just all blank. If I run the find command in a terminal, I get dozens of hits. I figure it's the way how I'm... (3 Replies)
Discussion started by: superbbrr
3 Replies

3. Shell Programming and Scripting

bash script won't execute (Mac)

I can't get any bash scripts to run in Terminal (Mac - Snow Leopard). I have the following super-simple script, and I can't get it to execute despite having the correct permissions (I think). #!/bin/bash echo "WORK... PLEASE?!" I named the file 'testScript.sh', and I added execution... (6 Replies)
Discussion started by: compulsiveguile
6 Replies

4. Solaris

Solaris 10u7 won't boot after hardware change

Hi all, I've somehow gained the idea that I _need_ to run at least 1 box with Solaris, but things don't go as I had planned :-) I pulled this ancient IBM eserver xseries 305 out of the dust, and got myself a fresh copy of the required cd's for Solaris 10u7. FAIL, for some reason the box and the... (7 Replies)
Discussion started by: mr.aart
7 Replies

5. UNIX for Dummies Questions & Answers

tip: Simple script won't run in cygwin - vim editor involved

I ran into this issue and thanks to various postings in various forums, was able to figure out the solution but didn't see one posting that laid the whole issue out cleanly. So thought the following might help others ... ------------------------------------------------------------------------... (2 Replies)
Discussion started by: oxysep
2 Replies

6. AIX

won't mount /usr...won't boot fully

Hello: NOOB here. I attempted to use smit mkcd. Failed on first attempt, not enough space. 2nd attempt tried to place iso on /usr, not enough space there. Cleanup ran for about 5 minutes after aborting. Now AIX won't boot. LCD display on 7029-6E3 says: 0517 MOUNT /USR. Attempted to boot from CD... (11 Replies)
Discussion started by: bbird
11 Replies

7. Solaris

smc won't run on a regular user

Hi All, I'm getting this all the time with a regular user (after I do su - and smc): It appears you are attempting to run the graphical Solaris Management Console from a terminal which does not have a suitable 'DISPLAY' environment. Please check your 'DISPLAY' settings and that the user... (5 Replies)
Discussion started by: itik
5 Replies

8. UNIX for Dummies Questions & Answers

Made command into a script but now won't run

Hello, After seeing in a Unix cheatsheet that I could add commands into a file and run that file as a command to save on typing, i tried it with this: #! /bin/csh # Backup website excluding directories that do not change rsync -e "ssh -p 2222" -axzvc --progress --stats --compress-level=9... (9 Replies)
Discussion started by: patwa
9 Replies

9. UNIX for Dummies Questions & Answers

Cron won't run properly

I am new to unix, and this is my 1st post on this board. Looking for some advice about a cron job in my server. I am running a cron task that references a script which runs several other scripts and compiles them into a report and emails it to me. If I run the script manually, I will... (2 Replies)
Discussion started by: Steeler_fan
2 Replies

10. UNIX for Dummies Questions & Answers

Why won't my script run?

On the following script that I get an error when I try to execute as root: #./mv_log.sh bash: /root/util/mv_log.sh: Permission denied #!/usr/bin datetag=`date --date='1 day ago' +"%b%d%Y"` logname=`find /opt/bea/wlserver6.1/config/*/logs/ -iname 'access.log0*' -mtime -1 -print` mv... (4 Replies)
Discussion started by: darthur
4 Replies
Login or Register to Ask a Question