Solved

variable size

Posted on 2000-04-05
8
236 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
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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help stop mail server from sending spam. 27 127
LINUX ZIP - UNCOMPRESS WINDOWS PATH 3 100
MarkLogic 1 79
Authenticate using sesu from script 7 32
Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

821 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