0

I have a script that I run from a Java GUI. It executes a SQL script and writes the results to a log file in the tmp directory. The rest of the script should open up an xterm and display the results of the output file to the screen. It creates the log file as supposed and it opens up an xterm as well. The only problem is that it freezes up after that point and I have to restart the whole process again. Here is an example of the script that I am using to open the xterm

#!/bin/csh -f



#set MYSQL=${MYSQL_HOME}/mysql
set PSQL=${PSQL_HOME}/psql
set MORE=/usr/xpg4/bin/more


set REPORT=/h/Scripts/DataValidation/ParametersDataReport.sql


#${REPORT}

${PSQL} ${USER}<${REPORT} 

#Get the number of lines in the report file for scrollbar control
#set lc='wc -l /tmp/results.log'
#echo $lc

#Open an extra terminal

set title="EARTH ORIENTATION PARAMETERS REPORT"

/usr/openwin/bin/xterm -T "$title" \
-bg lightblue -fg black -sb -sl 2000 -ut -e ${MORE}  \
-f /h/USERS/Pablito/results.log     \

exit

MORE and title are defined as variables in the script file. Why is my script crashing and causing the terminal to hang up? Could this be a segmentation fault?

I am doing all this through an ssh connection. I looked at the command issued and this is what it states:

/usr/openwin/bin/xterm -sb -ls -display@d&@;

I typed this command on the terminal and it displayed the results pretty well. Why can't I do this from the GUI?

/usr/openwin/bin/xterm -T EARTHORIENTATIONPARAMETER -geometry 104x50+0+80 -bg lightblue -fg black -sb -sl 2000 -ut -e /usr/xpg4/bin/more -f /tmp/results.log

When I try to use the GUI it just freezes up on me (meaning I cannot access the GUI or the terminal). It also contains an error

bg: Command not found

on the terminal where the GUI was launched.

I guess what I really should be asking is how to I execute the following command in a csh script because when I type it manually from the terminal it produces the desired effect

xterm -T "EarthOrientation Parameter" -geom 104x50+0+80 -bg pink -fg black -sb -sl   2000 -ut -e /usr/xpg4/bin/more -f /h/USERS/local/Pablito/results.log
Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
rambokayambo
  • 341
  • 4
  • 10
  • 27
  • You're invoking the `xterm` command in the foreground. That means that the script will wait until the `xterm` terminates -- i.e., until the terminal window closes. What happens when you close the xterm window? Also, you seem to be missing a backslash in your script (is it missing in your actual script or did you just make a typo when posting?), and the `exit` should be indented so it appears as part of the code block. – Keith Thompson Aug 06 '12 at 20:28
  • when i close the xterm it just shuts dowm and closes the GUI as well – rambokayambo Aug 06 '12 at 20:43
  • how can you tell that i am invoking the xterm in the background? i give the xterm command first and then it jusat hangs up sorry because of the type the backslash is missing – rambokayambo Aug 06 '12 at 20:44
  • Then it looks like the script is working correctly; it launches `xterm`, and terminates when the `xterm` window closes. I can't guess why the GUI closes; that would be something in your Java code that you haven't shown us. – Keith Thompson Aug 06 '12 at 20:45
  • "how can you tell that i am invoking the xterm in the background?" I said you're invoking the xterm in the foreground. To invoke it in the background, you'd need to follow the command with `&`. I have no idea whether you want to do that; should the program continue running while the `xterm` window is visible, or should it wait? – Keith Thompson Aug 06 '12 at 20:46
  • NO the script is NOT working correclty. It only reads and sets the titl;e for the xterm but doesnt set the other properties that need to be set so i do not believe it is working for instance where is my data from the log file ? the xterm it launches is completely empy and i cant scroll up or down? there is no way it is working correctly if it freezes up all windows and i have to start the taks manager and close it down – rambokayambo Aug 06 '12 at 20:48
  • it should wait but i think you misunderstand a bit. The script is supposed to launch the xterm and also display the information in the log file properly and all it is doing is lanching the xterm and setting the heading but it is not displaying any infor and it is freezing up and that point – rambokayambo Aug 06 '12 at 21:00
  • And you might as well read http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/ – Keith Thompson Aug 06 '12 at 22:27
  • Just a reminder: You can and should, if you're so inclined, upvote answers that you think are good ones, and accept an answer that solves your problem. – Keith Thompson Aug 07 '12 at 00:33

1 Answers1

1

I'll assume that the version of the script in your question matches the one you're actually running.

/usr/openwin/bin/xterm \
-title "$title"        \ 
-geometry 100x40+0+90
-bg lightblue -fg brown \
-sb -sl 2000 -ut
-e ${MORE} -F /tmp/results.log

If you're going to invoke this as a csh script, it needs a #!/bin/csh -f at the top, or you need to invoke it explicitly as csh -f script-name.

You're missing a couple of backslashes. Since there's no \ on the -geometry line, the lines following that are not passed as arguments to the xterm command. The code you've shown us is equivalent to:

/usr/openwin/bin/xterm -title "$title" -geometry 100x40+0+90
-geometry 100x40+0+90 -bg lightblue -fg brown sb -sl 2000 -ut 
-e ${MORE} -F /tmp/results.log

This should invoke xterm with no command specified, so it will run your default shell interactively. The following lines should produce error messages:

-geometry: Command not found.
-e: Command not found.

but if you're invoking the script from a GUI you likely wouldn't see those messages.

Adding \ characters at the end of the geometry and -sb lines should solve that problem.

Since the script invokes xterm in the foreground (without a trailing & on the command), the script will wait for the xterm window to close before terminating.

You say it "freezes up"; I'm not sure what you mean by that, but whatever happens after the xterm closes and the script terminates is going to be controlled by your Java GUI code, which you haven't shown us.

Again, I'm assuming that those backslashes are missing in the script you're actually running. If not, you need to update your question, showing us the exact script you're running.

UPDATE :

Apparently my assumption was incorrect; your actual script is quite different from one that originally appeared in your question.

I cannot emphasize strongly enough how important it is to copy-and-paste the exact script or program that is causing the problem, or a modified version of it that you've confirmed causes the same problem. If you try to post an approximation of the script, you're very likely to omit the code that causes the problem.

http://sscce.org/ discusses this, but the site appears to be down at the moment; the Google cache is here.

So here's the relevant portion of the script that's now in your question:

/usr/openwin/bin/xterm -T "$title" \
-bg lightblue -fg black -sb -sl 2000 -ut -e ${MORE}  \
-f /h/USERS/Pablito/results.log     \

exit

In a comment, you've said that you're getting an error something like

-bg Command is not found

That should really be in the question, since it's critical information for anyone trying to answer it.

(I suspect it's really -bg: Command not found.; again, exact copy-and-paste is as important for error messages as it is for code.)

I think the problem now is that you have a space after the backslash on the xterm line. A \ line continuation character must be at the very end of a line. If there's a space after the backslash, it's not treated as continuation character, and the next line will be treated as a separate command.

And the \ on the last line of your command is useless and potentially dangerous. It joins that line with the following line, which is empty and therefore probably harmless, but if you deleted that blank line it would pass the word exit as an argument to xterm.

The simplest workaround would be to modify your script so that the entire command is on one (very long) line with no backslashes.

Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
  • i have edited my original question with the most current script i am trying to execute – rambokayambo Aug 06 '12 at 21:08
  • it should execute statement -f /h/USERS/Pablito/results.log but instead it just stops at setting the title and freezes(both GUI and xterm screen still active but cannot be access ) – rambokayambo Aug 06 '12 at 21:17
  • The script now in your question has `-f h/USERS/Pablito/results.log`; shouldn't it be `-f /h/USERS/Pablito/results.log` ? Is the `exit` part of the script? If so, please insert 4 spaces in front of it so it appears as part of the code block. Why do you have a backslash after the last line of your command? Is there a blank line following it? If so, the backslash will join the blank line to your command, which is harmless, but you should delete the backslash anyway. – Keith Thompson Aug 06 '12 at 21:24
  • the xterm appears and it is just blank. It also cause everything else to freeze up and not be accessbile(this part makes sense sicne you said i should add the & to free up other processes) but what is weird is that the xterm is blank. Its almost like the script doesnt not exit and is waiting for some other command. -f h/USERS/Pablito/results.log is what should read whats in the log file to my xterm. exit is part of the script im sorry – rambokayambo Aug 06 '12 at 21:37
  • So it uses the path `h/USERS/Pablito/results.log` relative to the current directory, not the absolute path `/h/USERS/Pablito/results.log`? Are you sure that's what it should do? Are you sure that the current directory, when you invoke the script, is the one that contains the `h` subdirectory? And please answer my questions from my previous comment about backslashes and blank lines, and edit the question as I suggested so that `exit` shows up in the code block. – Keith Thompson Aug 06 '12 at 21:43
  • ok. So yes that is where the direcotry exists. Some new developmeents are that the xterm where i launch the GUI now states that -bg Command is not found yet it is listed as one of the options when launching an xterm windows? and i apologixe once again it uses the absolute path /h/USERS/Pablito/results.log and i will edit this – rambokayambo Aug 06 '12 at 21:47
  • ok i have edited the error that is printed out. You say that i dont need an extra space on the xterm line but i dont think this is true. How can you tell? does the computer really count the whitespace? – rambokayambo Aug 06 '12 at 22:35
  • @rambokayambo: As I just explained, the backslash *must* be at the very end of the line. I confirmed that it makes a difference before I posted my answer. Is there a space after the backslash? What happens if you delete it? – Keith Thompson Aug 06 '12 at 22:42
  • when i delete it it still hangs up – rambokayambo Aug 06 '12 at 22:47
  • So there *was* a space after the backslash? Please answer *all* the questions I ask; otherwise I can't help you. Does deleting the space make the `bg: Command not found` message go away? – Keith Thompson Aug 06 '12 at 22:49
  • ii cannot tell if there was a space or not because after that it is simple whitespace. Deleting whatever you thought was theres does not make the rror go away. I have tried to run the script directly from the xterm and it gives me the same error bg:command not found. I think i know why it is hanging up becase of the way my runshellscript method works. I am almost sure that it is a formatting problem this time around. Please look at my original post for the edit thgat i have made – rambokayambo Aug 06 '12 at 22:54
  • Is it `bg: Command not found` or is it `-bg: Command not found`? You certainly should be able to tell whether there was a space after the backslash by moving the cursor to the end of the line while editing the file; failing that, try `cat -A foo.csh` or `cat -e foo.csh`. – Keith Thompson Aug 06 '12 at 23:08
  • it is -bg: command not found and when i place my cursor at the enf of the line it immedialtley jumps to the next line and begins there so i dont believe there is an extra white space...please read my oribginal post. I think ijusty have to build a new script – rambokayambo Aug 06 '12 at 23:24
  • If you're getting `-bg: Command not found` (again, *please* copy-and-paste the error message), then the shell is interpreting the line starting with `-bg` as a separate command. I don't think you've given enough information to know why that's happening. If you put the entire command on one line without the backslashes, that will probably avoid the problem. – Keith Thompson Aug 06 '12 at 23:29
  • hey new advancements. I put it all as one line and it has produced the screen with the information from the file as expected. The only problem is that it sill freezes up and takes quite sometime to load but at least it is producing the contents of the file..i thank you for your patience man...now i have to fuigure out why it is freezing – rambokayambo Aug 06 '12 at 23:35
  • i have a feeling it has to do with my java class and why it hangs up after reading the output for some reason. it might be a java thing from this point on – rambokayambo Aug 06 '12 at 23:38
  • Then that should be a separate question (once you narrow it down enough to ask). – Keith Thompson Aug 06 '12 at 23:39