Sponsored Content
Full Discussion: Help with cmd while using ps
Top Forums Shell Programming and Scripting Help with cmd while using ps Post 302947605 by bakunin on Friday 19th of June 2015 11:46:07 AM
Old 06-19-2015
Quote:
Originally Posted by Jojo90
Code:
ps -e -o pid,uname,cmd

how can i split and take only the cmd part from it.
You can of course specifiy only the "cmd"-part in the option-string of ps like Aia has already suggested. If you need all three values you can split these in the shell:

Code:
ps -e -o pid,uname,cmd |\
while read PID UNAME CMD ; do
     print - "PID=$PID , user=$UNAME , command=$CMD"
done

If you use a read command to fill several variables (three in this case) the input to fill them (one line from the output of ps) will be split along word boundaries, so the first "word" goes to the first variable, the second word to the second variable. If there are more "words" in the output than there are variables the last variable gets the whole rest of the line.

So, this works because the first two values are always single "words" (character groups surrounded by blanks), only the last one isn't. It would not work if there would be several multi-word values involved.

I hope this helps.

bakunin
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

man <cmd> >> cmd.txt

I've noticed most of my postings here are because of syntax errors. So I want to begin compiling a large txt file that contains all the "man <cmd>" of the commands I most have problems with. I ran a "man nawk >> nawk.txt" but it included a header/footer on each "page". Anyone know how I'd be... (6 Replies)
Discussion started by: yongho
6 Replies

2. Programming

open cmd

if((LogFile=open(TempStr,O_CREAT|O_WRONLY|O_APPEND,0666))==-1) return(1); could someone explain me what the open() does here (2 Replies)
Discussion started by: bankpro
2 Replies

3. UNIX for Dummies Questions & Answers

mv cmd

Hi All, How can I move only files to another destination using mv cmd in hp-ux. (2 Replies)
Discussion started by: mhbd
2 Replies

4. UNIX for Dummies Questions & Answers

sed cmd

write the sed command for swapping the first and 2nd (fields)words in the following file input file cse1 rama 1223 cse2 raju 2453 cse3 sita 3523 i tried with this $sed 's/ \(*\)/ \(*\)/ \2,\1' myfile1 but not getting th required... (4 Replies)
Discussion started by: sankar_vitam
4 Replies

5. AIX

Filesystems cmd

hi is that any command to find out which filesystems occupying more process in cpu utilisation (4 Replies)
Discussion started by: senmak
4 Replies

6. Shell Programming and Scripting

Unix cmd prompt how to get old cmd run?

Hi, I am using SunOS I want to serch my previous command from unix prompt (like on AIX we can search by ESC -k) how to get in SunOs urgent help require. (10 Replies)
Discussion started by: RahulJoshi
10 Replies

7. Shell Programming and Scripting

Help with delete cmd

Is there any command to know ,how many files are deleted when rm *. cmd was excuted. I worte script which runs for 1 hours regularly and it is used to delete the .exe files but i need to know how many exe files are deleted regularly. Please let me know the cmd ---------- Post updated at... (3 Replies)
Discussion started by: kkalyan
3 Replies

8. Shell Programming and Scripting

Perl open(CMD, "cmd |"); buffering problem..

Hello, There's a third-party application's command that shows the application's status like "tail -f verybusy.log". When use the command, the output comes every 1-sec. but when it goes in a script below the output comes every 8-sec...What is the problem and how can I fix it? open(CMD,... (2 Replies)
Discussion started by: Shawn, Lee
2 Replies

9. UNIX for Dummies Questions & Answers

Help with the find cmd

Hello, I'm having a trouble with the find cmd. I would like to find all the java versions on my systems. I have solaris 9 & 10 RHEL and SUSIE. java -version doesn't give all the versions on the server. So I am trying to use the find command to find them all find / -name java I would... (7 Replies)
Discussion started by: bitlord
7 Replies

10. UNIX Desktop Questions & Answers

Sftp cmd

What is the cmd line to connect sftp, specifing the port number and the shh key file. When I use the below cmd format, it gives the msg :node name or service name not known, but I know the connection works, because the automated sftp script works fine and I can log into the remote server ... (3 Replies)
Discussion started by: ITDev01
3 Replies
TRACE-CMD.DAT(5)														  TRACE-CMD.DAT(5)

NAME
trace-cmd.dat - trace-cmd file format DESCRIPTION
The trace-cmd(1) utility produces a "trace.dat" file. The file may also be named anything depending if the user specifies a different output name, but it must have a certain binary format. The file is used by trace-cmd to save kernel traces into it and be able to extract the trace from it at a later point (see trace-cmd-report(1)). INITIAL FORMAT
The first three bytes contain the magic value: 0x17 0x08 0x44 The next 7 bytes contain the characters: "tracing" The next set of characters contain a null '' terminated string that contains the version of the file (for example): "6" The next 1 byte contains the flags for the file endianess: 0 = little endian 1 = big endian The next byte contains the number of bytes per "long" value: 4 - 32-bit long values 8 - 64-bit long values Note: This is the long size of the target's userspace. Not the kernel space size. [ Now all numbers are written in file defined endianess. ] The next 4 bytes are a 32-bit word that defines what the traced host machine page size was. HEADER INFO FORMAT
Directly after the initial format comes information about the trace headers recorded from the target box. The next 12 bytes contain the string: "header_page" The next 8 bytes are a 64-bit word containing the size of the page header information stored next. The next set of data is of the size read from the previous 8 bytes, and contains the data retrieved from debugfs/tracing/events/header_page. Note: The size of the second field fBcommitfR contains the target kernel long size. For example: field: local_t commit; offset:8; fBsize:8;fR signed:1; shows the kernel has a 64-bit long. The next 13 bytes contain the string: "header_event" The next 8 bytes are a 64-bit word containing the size of the event header information stored next. The next set of data is of the size read from the previous 8 bytes and contains the data retrieved from debugfs/tracing/events/header_event. This data allows the trace-cmd tool to know if the ring buffer format of the kernel made any changes. FTRACE EVENT FORMATS
Directly after the header information comes the information about the Ftrace specific events. These are the events used by the Ftrace plugins and are not enabled by the event tracing. The next 4 bytes contain a 32-bit word of the number of Ftrace event format files that are stored in the file. For the number of times defined by the previous 4 bytes is the following: 8 bytes for the size of the Ftrace event format file. The Ftrace event format file copied from the target machine: debugfs/tracing/events/ftrace/<event>/format EVENT FORMATS
Directly after the Ftrace formats comes the information about the event layout. The next 4 bytes are a 32-bit word containing the number of event systems that are stored in the file. These are the directories in debugfs/tracing/events excluding the fBftracefR directory. For the number of times defined by the previous 4 bytes is the following: A null-terminated string containing the system name. 4 bytes containing a 32-bit word containing the number of events within the system. For the number of times defined in the previous 4 bytes is the following: 8 bytes for the size of the event format file. The event format file copied from the target machine: debugfs/tracing/events/<system>/<event>/format KALLSYMS INFORMATION
Directly after the event formats comes the information of the mapping of function addresses to the function names. The next 4 bytes are a 32-bit word containing the size of the data holding the function mappings. The next set of data is of the size defined by the previous 4 bytes and contains the information from the target machine's file: /proc/kallsyms TRACE_PRINTK INFORMATION If a developer used trace_printk() within the kernel, it may store the format string outside the ring buffer. This information can be found in: debugfs/tracing/printk_formats The next 4 bytes are a 32-bit word containing the size of the data holding the printk formats. The next set of data is of the size defined by the previous 4 bytes and contains the information from debugfs/tracing/printk_formats. PROCESS INFORMATION
Directly after the trace_printk formats comes the information mapping a PID to a process name. The next 8 bytes contain a 64-bit word that holds the size of the data mapping the PID to a process name. The next set of data is of the size defined by the previous 8 bytes and contains the information from debugfs/tracing/saved_cmdlines. REST OF TRACE-CMD HEADER Directly after the process information comes the last bit of the trace.dat file header. The next 4 bytes are a 32-bit word defining the number of CPUs that were discovered on the target machine (and has matching trace data for it). The next 10 bytes are one of the following: "options " "latency " "flyrecord" If it is "options " then: The next 2 bytes are a 16-bit word defining the current option. If the the value is zero then there are no more options. Otherwise, the next 4 bytes contain a 32-bit word containing the option size. If the reader does not know how to handle the option it can simply skip it. Currently there are no options defined, but this is here to extend the data. The next option will be directly after the previous option, and the options ends with a zero in the option type field. The next 10 bytes after the options are one of the following: "latency " "flyrecord" which would follow the same as if options were not present. If the value is "latency ", then the rest of the file is simply ASCII text that was taken from the target's: debugfs/tracing/trace If the value is "flyrecord", the following is present: For the number of CPUs that were read earlier, the following is present: 8 bytes that are a 64-bit word containing the offset into the file that holds the data for the CPU. 8 bytes that are a 64-bit word containing the size of the CPU data at that offset. CPU DATA
The CPU data is located in the part of the file that is specified in the end of the header. Padding is placed between the header and the CPU data, placing the CPU data at a page aligned (target page) position in the file. This data is copied directly from the Ftrace ring buffer and is of the same format as the ring buffer specified by the event header files loaded in the header format file. The trace-cmd tool will try to fBmmap(2)fR the data page by page with the target's page size if possible. If it fails to mmap, it will just read the data instead. SEE ALSO
trace-cmd(1), trace-cmd-record(1), trace-cmd-report(1), trace-cmd-start(1), trace-cmd-stop(1), trace-cmd-extract(1), trace-cmd-reset(1), trace-cmd-split(1), trace-cmd-list(1), trace-cmd-listen(1), trace-cmd.dat(5) AUTHOR
Written by Steven Rostedt, <rostedt@goodmis.org[1]> RESOURCES
git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/trace-cmd.git COPYING
Copyright (C) 2010 Red Hat, Inc. Free use of this software is granted under the terms of the GNU Public License (GPL). NOTES
1. rostedt@goodmis.org mailto:rostedt@goodmis.org 06/11/2014 TRACE-CMD.DAT(5)
All times are GMT -4. The time now is 04:36 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy