carydb
asked on
variable size
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
COMMAND:
ps -ef | grep lmg > output.file
SHELL:
ksh
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.
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.
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
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/).
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/).
ASKER
Adjusted points from 10 to 20
ASKER
You have been a lot of help. Thanks. I will see about changing the ps code if I can. Thanks again!
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.