0

I want to execute the below command in loop for every second(till 1 hr) and need to capture in a log file. I want to make sure timestamps in those output file

/bin/ps -eo user,pid,ppid,pcpu,tty,pmem,args

could you please help?

4
  • Do you have access to ts utility? Commented Mar 16, 2020 at 22:42
  • no Paulo, I don't have access to ts Commented Mar 16, 2020 at 22:46
  • Would a loop like for (i=0;i<3600;i++) ; do /bin/ps -eo user,pid,ppid,pcpu,tty,pmem,args | sed "s/^/$i /" ; sleep 1 ;done > output.log work for you? Does it matter about the small time slippage?
    – icarus
    Commented Mar 16, 2020 at 23:03
  • Thanks a lot. It worked Commented Mar 16, 2020 at 23:40

1 Answer 1

0

Many ways to go about this. Here’s one assuming bash shell is available – since you didn’t state a preference:

timeout 1h bash -c 'while sleep 1 ; do date "+%F %T" ; /bin/ps -eo user,pid,ppid,pcpu,tty,pmem,args ; done' > yourfile.log
1
  • Thanks bxm. It says timeout command not found Commented Mar 16, 2020 at 23:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .