logging ps output


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users logging ps output
# 1  
Old 09-11-2006
Error logging ps output

i want to log the output of ps.
i want to see the ps outpıt line by line as i see in the stdout
but when i write it to a file it concatenates all lines
do you have any suggestion?

what i am using:
echo `ps -ef -o cmd,cpu,pcpu,cputime,nswap`>>log.txt

what i am getting:

Mon Sep 11 19:26:08 EEST 2006 CMD CP %CPU TIME NSWAP [kernel idle] 224 22.4 4-15:53:33 0 /sbin/init -a 0 0.0 2:15.24 0 [kproc_creato
r_d 0 0.0 0:00.96 0 [icsmsg_arr_nopr 0 0.0 0:00.00 0 [icssvr_nomem_da 0 0.0 0:00.00 0 [icssvr_throttle 0 0.0 0:00.00 0 [icssvr_daemo
n_f 0 0.0 0:01.03 0 [icssvr_daemon_f 0 0.0 0:00.00 0 [icssvr_nanny] 0 0.0 0:00.22 0 [icscli_throttle 0 0.0 0:00.00 0 [CFS daemon] 0
0.0 0:00.00 0 [icssvr_daemon_p 0 0.0 0:00.00 0 [icssvr_daemon_p 0 0.0 0:00.00 0 [icssvr_daemon_p 0 0.0 30:39.70 0 [icssvr_daemon_p 0
0.0 0:00.15 0 /sbin/kloadsrv 0 0.0 0:00.43 0 /sbin/hotswapd 0 0.0 0:00.51 0 [icssvr_daemon_p 0 0.0 0:00.32 0 /sbin/vold -k 0 0.0 0:
# 2  
Old 09-11-2006
lsoe the echo:
Code:
ps -ef -o cmd,cpu,pcpu,cputime,nswap >>log.txt

# 3  
Old 09-11-2006
thanks a lot, it works!
but, what is the explanation?
# 4  
Old 09-12-2006
A short answer is that echo does not call isatty to find out what stdout is talking to.
For an example of a program that "knows" what it's stdout is doing try this:

Code:
ls

ls | cat

ls gives you a set of columns, because it knows it's writing to a terminal humans read.
When the output is to a pipe, then it creates a long single column which is better for the reader program on the other end of a pipe.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Linux

Syslog not logging successful logging while unlocking server's console

When unlocking a Linux server's console there's no event indicating successful logging Is there a way I can fix this ? I have the following in my rsyslog.conf auth.info /var/log/secure authpriv.info /var/log/secure (1 Reply)
Discussion started by: walterthered
1 Replies

2. UNIX for Advanced & Expert Users

Not logging ftp connections in /var/adm/wtmpx file (in last command output)

Hi all, I have F5 load balancer on my system and checking service status by opening an ftp session in every 30 seconds. These ftp sessions are being logged in /var/adm/wtmpx and filling up the file. when i run the last command most of the output is this ftp session. I was wondering if there is a... (1 Reply)
Discussion started by: cepxat
1 Replies

3. Shell Programming and Scripting

Logging Remote SSH command (cannot log a java output)

Hi all I'm creating a script that runs a few commands on some boxes and everything can be logged EXCEPT the java -version command, there doesn't seem to be any output... Can anyone help explain why this does not work? Do I need to do something extra to append the output from the java... (3 Replies)
Discussion started by: Keepcase
3 Replies

4. UNIX for Dummies Questions & Answers

Automatic logging (capture screen output) of telnet/ssh sessions on a Solaris node

Hi I am working in Solaris 10 and I want to monitor logs for every telnet/ssh session that tries to connect to the server. I need these logs to be generated in a file that I can fetch using ftp. I am a new user and a stepwise detail will be great BR saGGee (3 Replies)
Discussion started by: saggee
3 Replies

5. Post Here to Contact Site Administrators and Moderators

Constant Logging In (After Logging Out)

Hi Everyone. First, I want to thank all of you for letting me participate in this great group. I am having a bit of a problem. After I get an email from a responder, I login to make my reply. In the mean time I get another response by email from another member, I go to reply to them and I... (6 Replies)
Discussion started by: Ccccc
6 Replies

6. UNIX for Dummies Questions & Answers

Logging Command Line and Output in Unix

Hi, This might be a bit stupid question, but what command to use to create like a session which logs the command line, and output on to the screen? Basically, a log to a file, where I can review what I had install, uninstall, etc. Thank you (4 Replies)
Discussion started by: kittoinc
4 Replies

7. Solaris

Logging commands and output

I'm looking for a CLI utility that will capture all the commands you type at the Solaris CLI (and their output) into a file. I'm sure it's called "scripter", but I can't find anything on a command called scripter. Does anyone know of a such a command? Your help will be greatly... (3 Replies)
Discussion started by: soliberus
3 Replies

8. Programming

serializing logging output mult. proc. inst deamon

Hello, i have an interresting topic today C++ on solaris. lgpl stuff applicable. My program is a deamon process wich takes input from network, then processes the data, and outputs reformatted to network. We're generating a lot of logging output. the logging is absolutely unbuffered at the... (3 Replies)
Discussion started by: heck
3 Replies

9. Shell Programming and Scripting

Redirection of output (for logging)

Hi, Currently I'm working on a lenghty script so I figured it would be useful to create a logfile so that output that is displayed on the users screen is also stored in the log file for later reference...... kinda like the whole point of a log file! Anyway, I was just wondering if there was an... (3 Replies)
Discussion started by: _Spare_Ribs_
3 Replies

10. UNIX for Dummies Questions & Answers

Asking about logging in

Hi, just wriiten a sh script and as my script will try to log into another server to delete some files but when i run , it keeps on saying that my files do not exist. It seems to refer to my local directory instead. Below is my script : FTP_HOST=ip_number FTP_USER="user password" ... (1 Reply)
Discussion started by: blueberry80
1 Replies
Login or Register to Ask a Question