Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

variable size

Posted on 2000-04-05
8
Medium Priority
?
275 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
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.:
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…

647 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