?
Solved

variable size

Posted on 2000-04-05
8
Medium Priority
?
264 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
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
LVL 14

Accepted Solution

by:
chris_calabrese earned 80 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Suggested Courses

762 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