Solved

variable size

Posted on 2000-04-05
8
254 Views
Last Modified: 2010-04-21
I have a shell program that issues a command and redirects the resulting output to a file.  The output, in some cases, is 165 characters long. Only 126 characters are being written to the file via the redirect! How can I make it write the entire line to file instead of truncating at 126 chars?
COMMAND:
ps -ef | grep lmg > output.file
SHELL:
ksh
0
Comment
Question by:carydb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 14

Expert Comment

by:chris_calabrese
ID: 2687564
Given the way that the shell sets up the redirection, it is highly unlikely that this is part of the problem.  Are you sure the output is different with and without the redirect.

I'm guessing that the 'full width' output is coming from the ps when going straight to the terminal without first passing through the pipe to grep.  Perhaps the version of ps you are using has different behavior when dealing with pipes vs terminals, or the version of grep is truncating the line.
0
 
LVL 2

Expert Comment

by:festive
ID: 2688250
you could also do something like:
LOGFILE="logfile.log"
exec 1>$LOGFILE 2>&1

this will redirect all script/error output to the logfile and may help locate the problem.

you can try different switches with ps also to give more/less details.
0
 
LVL 1

Expert Comment

by:Astroman
ID: 2690198
if you do

ps -ef | grep lmg | tee output.file

You will get the output both on the screen, and in the file. That might help see what's happening.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Accepted Solution

by:
chris_calabrese earned 20 total points
ID: 2690739
Again, I'm guessing that the problem is that either ps is changing its behavior going to a pipe vs the terminal or that grep itself is the culprit.  No ammount of changing how the shell or some other program ends up eventually executing
  filedes=open(filename, O_CREAT);
  close(1);
  dup2(filedes, 1);
is going to change this.

Step 1:
  Run just 'ps -ef' to the terminal and see what you get.

Step 2:
  Run 'ps -ef | more' t and see what you get.  If this is different than in step 1, the problem lies with ps changing its behavior when dealing with a pipe vs a terminal.  Some versions of ps support -w, -ww, and/or -www to specify full-width output in these situations.

Step 3:
  Run just the 'ps -ef | grep lmg | more'  without the redirect and see what you get.  If this is different than in step 2, the grep is to blame.  Try the GNU grep from www.gnu.org if this is the case.

Step 4:
  Run the whole 'ps -ef | grep lmg > output.file' and see what you get.  If this is different than in Step 3, you must be using a very very strange shell that does not implement redirection properly.  Trhy a different shell.
0
 

Author Comment

by:carydb
ID: 2690964
Chris (chris_calabrese).  I thought that ps -ef was printing the entire line to screen, but it is not.  I guess the issue is that ps is truncating the output to screen.  I did not find a -w option in the ps man page.  Any suggestions on how I can get an untruncated output from ps?  Thanks
0
 
LVL 14

Expert Comment

by:chris_calabrese
ID: 2691254
Is the behavior different between a pipe and terminal on the ps output, or is it that ps is simply never showing you the full command line you want?

If it's the former, you might be able to fool ps into thinking the output is a terminal by the clever use of pseudo terminals - easiest if you use the expect tool.

If it is always truncating the line, there's probably not much you can do short of getting the source code to your version of ps (assuming open source or you have a source licence) and modifying it.  You might also be able to start with the source code to the 'top' program (try http://hpux.cs.utah.edu/hppd/hpux/Sysadmin/top-3.5beta9/).
0
 

Author Comment

by:carydb
ID: 2691294
Adjusted points from 10 to 20
0
 

Author Comment

by:carydb
ID: 2691295
You have been a lot of help. Thanks. I will see about changing the ps code if I can. Thanks again!
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question