Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get xterm -exec to execute two commands

Status
Not open for further replies.

Benjamin

Programmer
Jan 12, 2000
10
0
0
US
Hi,<br>
<br>
I'm trying to write a script that would open an xterm window and use the<br>
-exec to execute a tail command which passes the result to an awk command.<br>
<br>
xterm -exec tail file.log ¦ awk {parses data and prints out} &<br>
<br>
The problem is that the command awk is not executed. I heard from a friend<br>
that -exec only takes in one command. Is there another way to do this? I<br>
really need to get this working as a dealine is approaching. Any help would<br>
be greatly appreciated.<br>
<br>
Thank you.<br>
Benjamin<br>
<A HREF="mailto:benjaminle@engineer.com">benjaminle@engineer.com</A>
 
I have not tried this before but I believe -exec has to be the las command on the command line so everything after has to be one command. Have you tried containing the whole expresion inside ` ` i.e. xterm -exec `tail file.log ¦ awk {parses data and prints out} &`<br>
Just a guess but it may be worth a try.<br>
<br>
<p>Ged Jones<br><a href=mailto:gedejones@hotmail.com>gedejones@hotmail.com</a><br><a href= > </a><br>
 
Alternatively, put the &quot;tail file.log ¦ awk {parses data and prints out} &&quot; into a shell script, and pass the shell script name as the argument to -exec.<br>
<br>
Something to watch out for if you try Ged's suggestion is which quotes you use to surround your command. If you use the backtick quotes - ` - then the command within them will execute, and the -exec option will try to execute the output from your awk... Double quotes - &quot; - would be better.<br>
<br>
HTH.
 
Thanks Ged & Andy,<br>
<br>
I try both the suggested methods above but it does not seem to work:<br>
<br>
The following hangs the xterm:<br>
xterm -exec `tail file.log ¦ awk {parses data and prints out}` &<br>
<br>
The following returns an error message:<br>
xterm -exec &quot;tail file.log ¦ awk {parses data and prints out}&quot; &<br>
---&gt; xterm: Can't execvp tail file.log ¦ awk {parses data and prints out}<br>
<br>
I also try putting the tail and awk commands into one script and have xterm<br>
execute it but that does not work either.<br>
<br>
Any other suggestions would be appreciated. Thank you.<br>
<br>
Regards,<br>
Ben
 
You might want to try to run a background job script right ahead of the xterm command. The background job would sleep for 5 or 10 seconds before it runs the tail command.
 
Hi Mrregan,<br>
<br>
I don't really understand your suggestion. If I run a background job (i.e. tail) before the xterm even in the background, wouldn't the results of the tail command be sent to the terminal that calls it instead of the new xterm? Maybe I'm missing something, can you fill in that missing piece? Thanks a lot.<br>
<br>
Regards,<br>
Ben<br>
<A HREF="mailto:benjaminle@engineer.com">benjaminle@engineer.com</A>
 
Ben,<br>
I was presuming that xterm would output to a log file when it executed. The sleeping command would tail that log file and parse it to a printer or another file when it 'wakes up' after the xterm command had executed.
 
Hi Mrregan again,<br>
<br>
The xterm only execute a command that tails a log file. That can easily be done with the xterm -exec command. The problem I run into is that I want to print only selected portions of the log file. I want the tail command to passed its data to an awk script to parse the log information and print it out to screen. The xterm command sees the tail command but not the awk script even though the pipe there (as in the description above).<br>
<br>
I try to run the awk script on the (ever increasing) log file first and redirect that to another file. Then have xterm just tail that new file. The result is not very pretty. Instead of tailing the new file line by line, it waits a while and clumps dozens of line out to the screen all at once, many times the last line is cut off in the middle.<br>
<br>
Thanks for reading,<br>
Ben<br>
<A HREF="mailto:benjaminle@engineer.com">benjaminle@engineer.com</A>
 
Should have asked this sooner, but which Unix are you running? Although all 'xterm' commands are supposed to be the same, we may be hitting a vendor specific problem here.<br>
<br>
Just a thought.
 
I think mrregan was implying somethinng like this: -<br>
1st run -<br>
xterm -exec tail file.log &gt; file.newlog &<br>
then run -<br>
cat file.newlog ¦ awk {parses data and prints out} &<br>
<br>
<br>
<br>
<p>Ged Jones<br><a href=mailto:gedejones@hotmail.com>gedejones@hotmail.com</a><br><a href= > </a><br>
 
Thanks to everyone for pitching in to help. The Unix OS we use is IRIX 6.4. And yes, I did try:<br>
<br>
xterm -exec tail -f logfile &gt; logfile.new &<br>
tail -f logfile.new ¦ awk {...} &<br>
<br>
The result is that xterm pops up in a new window and outputs the log onto the xterm but the logfile.new is created with no data written to it. The awk script is useless in this case.<br>
<br>
tail -f logfile ¦ awk {...} &lt;-- works for the current window that execute this commands. For many log files, this might look like a mess since all don't have the same format. That is why I try to pop up different windows for different logs.<br>
<br>
As mentioned above, there might be a limitation to the IRIX 6.4 xterm -exec command but for every limitation, there is a work around (I hope).<br>
<br>
Regards,<br>
Ben<br>
<A HREF="mailto:benjaminle@engineer.com">benjaminle@engineer.com</A>
 
You did not mention which shell you were using either.<br>
<br>
You could also try following the redirect to logfile.new with 1&gt;&2 i.e.<br>
&gt;logfile.new 1&gt;&2<br>
Thuis should associate the file descriptors for the two processes. Mihght be worth a try. <p>Ged Jones<br><a href=mailto:gedejones@hotmail.com>gedejones@hotmail.com</a><br><a href= > </a><br>
 
This is probably the last message for this thread. I just found out a mistake I did while working on the scripts above. It turned out that two solutions works if I only I had change the permission of the script to executable... I've been bonking myself on the head ever since I found that out. Such a stupid mistake. I could hear all my friends laughing at me now.<br>
<br>
The two solutions that works are:<br>
1)<br>
xterm -e script_a.csh &<br>
<br>
script_a.csh contains:<br>
tail -f filename.log ¦ awk {formatting}<br>
<br>
2)<br>
xterm -e c_executable &<br>
<br>
c_executable.c contains:<br>
....<br>
system (&quot;script_a.csh&quot;)<br>
....<br>
<br>
It was after I got (2) to work did I noticed the permission problem of script_a.csh. What happened was that I changed the permission of script_a.csh before but deleted it and created a new one. The new one never worked due to it being only a read/write file. Thanks to everyone who respond to my question above.<br>
<br>
Regards,<br>
Ben<br>
<A HREF="mailto:benjaminle@engineer.com">benjaminle@engineer.com</A>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top