0

I am trying to retrieve the time in seconds from the process that started. But I am able to get just the day but not the complete date time. Below is the thing that I made:

ps --user <user Name> -o uid,pid,lstart,cmd:50 --no-heading |
    tail -n +2 |

    while read PROC_UID PROC_PID PROC_LSTART PROC_CMD; do

    echo $PROC_LSTART

    done

Thu
Tue
Fri
Thu
Thu

While the lstart should give me something like :   

Thu Jan 26 09:00:21 2017

Naga Vemprala
  • 718
  • 3
  • 16
  • 38

1 Answers1

1

The "read" command reads a space character as a field delimiter, so it is reading the lstart output as five separate fields, not a single field. Try this:

ps --user <user Name> -o uid,pid,lstart,cmd:50 --no-heading | tail -n +2 |
while read PROC_UID PROC_PID PROC_L1 PROC_L2 PROC_L3 PROC_L4 PROC_L5 PROC_CMD; do
  echo $PROC_L1 $PROC_L2 $PROC_L3 $PROC_L4 $PROC_L5
done
Leslie
  • 618
  • 4
  • 14
  • This helps. Is there a way to change the delimiter? – Naga Vemprala Feb 24 '17 at 16:15
  • Glad I could help. To answer your latest question, yes, using AIX format descriptors, but unfortunately they don't support the LSTART field (at least on CentOS 6, which is what I use). See this thread: http://stackoverflow.com/questions/3114741/generating-a-csv-list-from-linux-ps – Leslie Feb 24 '17 at 17:37