How to record PID and its command every 15s?
Clash Royale CLAN TAG#URR8PPP
up vote
-1
down vote
favorite
For troubleshooting purpose, I'd like to record PID and its command every 15s and write them to a text file.
The desired output:
TimeStamp, PID, Command
linux process ps top htop
add a comment |Â
up vote
-1
down vote
favorite
For troubleshooting purpose, I'd like to record PID and its command every 15s and write them to a text file.
The desired output:
TimeStamp, PID, Command
linux process ps top htop
add a comment |Â
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
For troubleshooting purpose, I'd like to record PID and its command every 15s and write them to a text file.
The desired output:
TimeStamp, PID, Command
linux process ps top htop
For troubleshooting purpose, I'd like to record PID and its command every 15s and write them to a text file.
The desired output:
TimeStamp, PID, Command
linux process ps top htop
linux process ps top htop
asked 1 hour ago
John Hass
1524
1524
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
0
down vote
This will get you you the three columns you want:
$ ps -hopid,comm | perl -anle'print time, ", $F[0], $F[1]"'
1541626566, 6496, gedit
1541626566, 7513, bash
You can limit or extend the scope of ps
, ie. what processes it lists. Then you put this in a loop with redirection.
while true; do echo x; sleep 15; done > out
Replace echo x
with the command proper and out
with the file name you choose.
As for the command producing the information, here's a run-down.
ps -hopid,comm
-ps
is obvious,-h
turns off the header line and-o
stands for the output (PID and command).- This goes to the Perl command, namely
perl -anle'print time, ", $F[0], $F[1]"'
. Hereperl
is Perl. The-anle
flags reprent correspondingly:a
- load input into an array,n
- take care of new lines,l
- process each single line, and finallye
- execute the code that follows. - And now the code follows:
'print time, ", $F[0], $F[1]"'
. First print the time stamp, then the first column of the array that holds the input material, and then the second.
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
This will get you you the three columns you want:
$ ps -hopid,comm | perl -anle'print time, ", $F[0], $F[1]"'
1541626566, 6496, gedit
1541626566, 7513, bash
You can limit or extend the scope of ps
, ie. what processes it lists. Then you put this in a loop with redirection.
while true; do echo x; sleep 15; done > out
Replace echo x
with the command proper and out
with the file name you choose.
As for the command producing the information, here's a run-down.
ps -hopid,comm
-ps
is obvious,-h
turns off the header line and-o
stands for the output (PID and command).- This goes to the Perl command, namely
perl -anle'print time, ", $F[0], $F[1]"'
. Hereperl
is Perl. The-anle
flags reprent correspondingly:a
- load input into an array,n
- take care of new lines,l
- process each single line, and finallye
- execute the code that follows. - And now the code follows:
'print time, ", $F[0], $F[1]"'
. First print the time stamp, then the first column of the array that holds the input material, and then the second.
add a comment |Â
up vote
0
down vote
This will get you you the three columns you want:
$ ps -hopid,comm | perl -anle'print time, ", $F[0], $F[1]"'
1541626566, 6496, gedit
1541626566, 7513, bash
You can limit or extend the scope of ps
, ie. what processes it lists. Then you put this in a loop with redirection.
while true; do echo x; sleep 15; done > out
Replace echo x
with the command proper and out
with the file name you choose.
As for the command producing the information, here's a run-down.
ps -hopid,comm
-ps
is obvious,-h
turns off the header line and-o
stands for the output (PID and command).- This goes to the Perl command, namely
perl -anle'print time, ", $F[0], $F[1]"'
. Hereperl
is Perl. The-anle
flags reprent correspondingly:a
- load input into an array,n
- take care of new lines,l
- process each single line, and finallye
- execute the code that follows. - And now the code follows:
'print time, ", $F[0], $F[1]"'
. First print the time stamp, then the first column of the array that holds the input material, and then the second.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
This will get you you the three columns you want:
$ ps -hopid,comm | perl -anle'print time, ", $F[0], $F[1]"'
1541626566, 6496, gedit
1541626566, 7513, bash
You can limit or extend the scope of ps
, ie. what processes it lists. Then you put this in a loop with redirection.
while true; do echo x; sleep 15; done > out
Replace echo x
with the command proper and out
with the file name you choose.
As for the command producing the information, here's a run-down.
ps -hopid,comm
-ps
is obvious,-h
turns off the header line and-o
stands for the output (PID and command).- This goes to the Perl command, namely
perl -anle'print time, ", $F[0], $F[1]"'
. Hereperl
is Perl. The-anle
flags reprent correspondingly:a
- load input into an array,n
- take care of new lines,l
- process each single line, and finallye
- execute the code that follows. - And now the code follows:
'print time, ", $F[0], $F[1]"'
. First print the time stamp, then the first column of the array that holds the input material, and then the second.
This will get you you the three columns you want:
$ ps -hopid,comm | perl -anle'print time, ", $F[0], $F[1]"'
1541626566, 6496, gedit
1541626566, 7513, bash
You can limit or extend the scope of ps
, ie. what processes it lists. Then you put this in a loop with redirection.
while true; do echo x; sleep 15; done > out
Replace echo x
with the command proper and out
with the file name you choose.
As for the command producing the information, here's a run-down.
ps -hopid,comm
-ps
is obvious,-h
turns off the header line and-o
stands for the output (PID and command).- This goes to the Perl command, namely
perl -anle'print time, ", $F[0], $F[1]"'
. Hereperl
is Perl. The-anle
flags reprent correspondingly:a
- load input into an array,n
- take care of new lines,l
- process each single line, and finallye
- execute the code that follows. - And now the code follows:
'print time, ", $F[0], $F[1]"'
. First print the time stamp, then the first column of the array that holds the input material, and then the second.
edited 43 mins ago
answered 52 mins ago
Tomasz
8,62052761
8,62052761
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f480456%2fhow-to-record-pid-and-its-command-every-15s%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password